Bubble Sort program

Discuss software for the Apple 1/replica 1

Bubble Sort program

Postby foresmac » May Mon 08, 2006 4:27 am

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 BASIC
110 REM ** BY CHRIS FORESMAN, 2006
120 REM ** BASED ON KELLEY & POHL, 1998
130 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 N
185 DIM A(N)
190 PRINT "NOW INPUT THE NUMBERS:"
200 FOR K=1 TO N
300 INPUT "ENTER NUMBER", A(K)
310 NEXT K
320 PRINT "SORTING..."
330 GOSUB 500
340 PRINT "HERE IS THE SORTED LIST:"
350 FOR K=1 TO (N-1)
360 PRINT A(K);", ";
365 NEXT K
370 PRINT A(N);"."
380 PRINT "THANK YOU."
390 END
500 REM ** SORT SUBROUTINE
510 FOR I=1 TO (N-1) STEP 1
520 FOR J=N TO (I+1) STEP -1
530 IF A(J-1) > A(J) THEN GOSUB 600
540 NEXT J
550 NEXT I
560 RETURN
600 REM ** SWAP SUBROUTINE
610 T = A(J-1)
620 A(J-1) = A(J)
630 A(J) = T
640 RETURN
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am

Return to Software

Who is online

Users browsing this forum: No registered users and 2 guests

cron