home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / BASIC / BASIC00.ZIP / SHELSORT.BAS < prev    next >
Encoding:
BASIC Source File  |  1987-01-11  |  1.4 KB  |  42 lines

  1. 100 '    SHELSORT        Submitted by Bob Noble
  2. 110 '
  3. 120 '           This program sorts ten random integers between 1 and 100 in
  4. 130 '           ascending order. It is a binary sort and is relatively fast.
  5. 140 '           The coding can esaily be converted to handle strings for gen-
  6. 150 '          eral use.
  7. 160 '
  8. 170 '           I have modified this listing for use in IBM PC BASIC from
  9. 180 '           the following source:
  10. 190 '
  11. 200 '                   Grillo, John P. and J.D. Richardson, DATA MANAGEMENT
  12. 210 '                   TECHNIQUES, Dubuque, Iowa: Wm. C. Brown Co., 1981.
  13. 220 '
  14. 230 CLS: KEY OFF: PRINT: DIM D(100): DEFINT D: RANDOMIZE
  15. 240 PRINT
  16. 250 FOR I = 1 TO 10: D(I) = RND*100: NEXT I
  17. 260 '
  18. 270 PRINT "Pass #   Position ->";
  19. 280 FOR I = 1 TO 10: PRINT TAB(20 + I * 4);I;: NEXT I
  20. 290 PRINT: PRINT: P = 0: N = 10: GOSUB 460
  21. 300 GOSUB 340
  22. 310 GOTO 490
  23. 320 '
  24. 330 ' * * * * * * * * * * Shell Sort * * * * * * * * * *
  25. 340 P = N
  26. 350   IF P <= 1 THEN RETURN
  27. 360 P = INT(P/2): M = N-P
  28. 370 F = 0
  29. 380 FOR J = 1 TO M
  30. 390   X = J+P
  31. 400     IF D(J) > D(X) THEN T = D(J): D(J) = D(X): D(X) = T: F = 1
  32. 410 NEXT J
  33. 420   IF F > 0 THEN 370
  34. 430 GOSUB 460: GOTO 350
  35. 440 '
  36. 450 ' * * * * * * * * * * Print Results * * * * * * * *
  37. 460 PRINT P; TAB(7); "D";
  38. 470 FOR I = 1 TO N: PRINT TAB(20+I*4); D(I);: NEXT I
  39. 480 PRINT: RETURN
  40. 490 PRINT: KEY ON: END
  41. *
  42. 460 PRINT P; TAB(7