Sorting algorithms/Selection sort: Difference between revisions

m
Line 703:
70 I=0: J=0: IMAX = 0: ITP! = 0: TL! = 0
80 '
90 ' CONSTCLS
130100 PRINT "This program does the Selection Sort Algorithm"
100 FALSE=0: TRUE=NOT FALSE
140110 INPUT "Number of elements to sort (Max=1000, Enter=10)";IMAX
110 '
160120 IF IMAX >= 10000 THEN IMAX = 100010
120 CLS
130 IF IMAX > 1000 THEN IMAX = 1000
130 PRINT "This program does the Selection Sort Algorithm"
170140 DIM N(IMAX)
140 INPUT "Number of elements to sort (Max=1000, Enter=10)";IMAX
150 IF' IMAXCreates =and 0shows THENthe IMAXunsorted = 10list
190160 RANDOMIZE TIMER
160 IF IMAX > 1000 THEN IMAX = 1000
170 FOR I=1 TO IMAX: N(I) = I: NEXT I
170 DIM N(IMAX)
180 FOR I=1 TO IMAX
180 ' Creates and shows the unsorted list
240190 J = INT(RND*IMAX)+1
190 RANDOMIZE TIMER
200 FOR I=1 TOSWAP N(I), IMAXN(J)
210 N(I) =NEXT I
220 PRINT: PRINT "Unsorted list:";
220 NEXT I
230 FOR I=1 TO IMAX: PRINT N(I);: NEXT I
240 PRINT: PRINT
240 J = INT(RND*IMAX)+1
300250 ' Sorts the list through the Selection Sort Algorithm and shows the results
250 SWAP N(I), N(J)
260 NEXTTL! I= TIMER
270 PRINT: PRINT "UnsortedSorting"; list:IMAX; "numbers";
280 FORCOLOR I=1 TO IMAX7+16: PRINTX N= POS(I0): PRINT"...";: NEXTCOLOR I7
290 PRINT:ITP PRINT= 0
300 FOR I=1 TO IMAX-1
300 ' Sorts the list through the Selection Sort Algorithm and shows the results
310 TL! FOR J=I+1 TO TIMERIMAX
370320 IF N(I)>N(J) THEN SWAP N(I), N(J): ITP! = ITP! + 1
320 PRINT "Sorting"; IMAX; "numbers";
220330 NEXT J, I
330 COLOR 7+16: X = POS(0): PRINT"...";: COLOR 7
390340 LOCATE ,X: PRINT ". Done!"
340 ITP = 0
350 FORPRINT: I=1PRINT TO"Sorted IMAX-1list:";
360 FOR J=I+=1 TO IMAX: PRINT N(I);: NEXT I
370 ' Final results
370 IF N(I)>N(J) THEN SWAP N(I), N(J): ITP! = ITP! + 1
430380 PRINT: PRINT: PRINT "Numbers sorted:"; IMAX
380 NEXT J, I
440390 PRINT "Total permutations done:";ITP!
390 LOCATE ,X: PRINT ". Done!"
400 PRINT: PRINT "SortedTime listlapse:"; TIMER-TL!; "seconds."
410 FOR I=1 TO IMAX: PRINT N(I);: NEXT I
420 'PRINT Final"End resultsof program"
480430 END
430 PRINT: PRINT: PRINT "Numbers sorted:"; IMAX
440 PRINT "Total permutations done:";ITP!
450 PRINT "Time lapse:"; TIMER-TL!; "seconds."
460 PRINT
470 PRINT "End of program"
480 END
</lang>
 
58

edits