## Bubble Sort program

Discuss software for the Apple 1/replica 1

### Bubble Sort program

Here is one of the programs I wrote for my project. Since I had trouble getting the machine to operate fully before I had to turn it in for grading, I couldn't test it out. Feel free to do so if you like, and let me know how it works.

The actual sort algorithm is actually pretty short, and consists of two small subroutines at the end. Other other stuff is just more or less getting the user to input the values to be sorted.

I thought I might be able to use it for a simple statistics program that would calculate mean, median, mode, and std dev for a list of grades.

Anyhowways, here is the code. Enjoy!
Code: Select all
`100 REM ** BUBBLE SORT DEMO IN APPLE I BASIC110 REM ** BY CHRIS FORESMAN, 2006120 REM ** BASED ON KELLEY & POHL, 1998130 PRINT "WELCOME TO THE SORTING PROGRAM."140 PRINT "YOU CAN INPUT A LIST OF NUMBERS, AND I CAN"150 PRINT "SORT THEM FOR YOU."160 PRINT ""170 PRINT "FIRST, TELL ME HOW MANY NUMBERS YOU HAVE:"180 INPUT N185 DIM A(N)190 PRINT "NOW INPUT THE NUMBERS:"200 FOR K=1 TO N300 INPUT "ENTER NUMBER", A(K)310 NEXT K320 PRINT "SORTING..."330 GOSUB 500340 PRINT "HERE IS THE SORTED LIST:"350 FOR K=1 TO (N-1)360 PRINT A(K);", ";365 NEXT K370 PRINT A(N);"."380 PRINT "THANK YOU."390 END500 REM ** SORT SUBROUTINE510 FOR I=1 TO (N-1) STEP 1520 FOR J=N TO (I+1) STEP -1530 IF A(J-1) > A(J) THEN GOSUB 600540 NEXT J550 NEXT I560 RETURN600 REM ** SWAP SUBROUTINE610 T = A(J-1)620 A(J-1) = A(J)630 A(J) = T640 RETURN` foresmac

Posts: 16
Joined: Feb Mon 13, 2006 12:48 am 