home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n05.zip / SORT.BAS < prev    next >
BASIC Source File  |  1989-02-06  |  971b  |  40 lines

  1.  
  2.      DEFINT A-Z
  3.      CLS
  4.  
  5.      DIM Array(20)        'create and fill a test array
  6.      FOR X = 0 TO 20
  7.          Array(X) = RND(1) * 1000
  8.          PRINT Array(X)
  9.      NEXT
  10.  
  11.      Done = -1            'this is required to initialize Sort
  12.      DO
  13.         PRINT ".";        'do anything you want here
  14.         GOSUB BSort
  15.      LOOP UNTIL Done
  16.  
  17.      FOR X = 0 TO 20      'show that it was sorted correctly
  18.          LOCATE X + 1, 15
  19.          PRINT Array(X)
  20.      NEXT
  21.      END
  22.  
  23.      BSort:
  24.          IF NOT Done GOTO MoreSort
  25.          Size = UBOUND(Array, 1) - 1
  26.          LoLimit = LBOUND(Array, 1)
  27.          Done = 0
  28.          FOR X = Size TO LoBound STEP -1
  29.              FOR Y = LoBound TO X
  30.                  IF Array(Y) > Array(Y + 1) THEN
  31.                     SWAP Array(Y), Array(Y + 1)
  32.                  END IF
  33.              NEXT
  34.              RETURN       'exit after each pass
  35.      MoreSort:
  36.          NEXT
  37.          Done = -1
  38.      RETURN
  39.  
  40.