home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
451-475
/
apd453
/
bubblesort.amos
/
bubblesort.amosSourceCode
Wrap
AMOS Source Code
|
1993-01-08
|
1KB
|
69 lines
' Quicksort.
' Robert Farnsworth.
' 1 Vidivoc Ave
' Mildura, 3500
' Jan. 91.
' If you need to sort more than
' a single dimension array, try
' this.
' Times:
' Quicksort Bubble sort
' 10 0.4 0.4
' 100 0.8 4.6
' 500 5.4 117.1
' 1000 11.7 452.0
' 2000 26.4 ?
' 4000 56.5 ?
' 8000 124.8 ?
' The times are now lower than above,
' now using Swap.
Set Buffer 100
'
Input "Array Size ";A
'
Dim ARRAY1(A),ARRAY2(A)
Global ARRAY1(),ARRAY2()
Print A;" numbers"
For I=1 To A
ARRAY1(I)=Rnd(2000000) : ARRAY2(I)=ARRAY1(I)
Next
Print "Sorting..."
Timer=0
BUBBLE[1,A]
E=Timer
Print "Bubble";
Print(E-S)/50.0
Timer=0
QUICKSORT[1,A]
E=Timer
Print "Quick sort";
Print(E-S)/50.0
Boom
End
Procedure QUICKSORT[LO,HI]
If LO<HI
K=ARRAY2(LO) : L=LO : H=HI
While L<>H
While H>L and K<=ARRAY2(H)
Dec H
Wend
Swap ARRAY2(L),ARRAY2(H)
While L<H and K=>ARRAY2(L)
Inc L
Wend
Swap ARRAY2(L),ARRAY2(H)
Wend
QUICKSORT[LO,L-1]
QUICKSORT[H+1,HI]
End If
End Proc
Procedure BUBBLE[LO,HI]
Shared ARRAY1()
For J=HI-1 To LO Step -1
For I=LO To J
If ARRAY1(I)>ARRAY1(I+1)
T=ARRAY1(I) : ARRAY1(I)=ARRAY1(I+1) : ARRAY1(I+1)=T
End If
Next
Next
End Proc