home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
501-525
/
apd520
/
asstd_programs
/
quicksort.amos
/
quicksort.amosSourceCode
Wrap
AMOS Source Code
|
1991-01-19
|
2KB
|
88 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.
'--------------------------------
'!!!!!!!!!!!!!!!!!!! NOTE TO MANDARIN !!!!!!!!!!!!!!!!!!!!!!!
'
' Had a lot of trouble writing this, computer kept crashing.
' Two problems:
'
' 1) With A=2000 I was greeted by the AMOS `message of doom'
' requester while the quicksort routine was executing.
' Had to use Set Buffer.
' 2) The Input statement (rem'd out) also crashed my poor
' old 1000 when I entered 1000 - not every time, but often.
' Everthing just froze. Had to eliminate Input statement.
'
' Wonder if this happens on a 500?
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Set Buffer 100
'
'Input "Array Size ";A
'
A=1000
Dim ARRAY(A)
Global ARRAY()
Print A;" numbers"
For I=1 To A
ARRAY(I)=Rnd(2000000)
Next
'
Print "Sorting..."
Timer=0
'BUBBLE[1,A]
QUICKSORT[1,A]
E=Timer
Print(E-S)/50.0
Boom
End
'
Procedure QUICKSORT[LO,HI]
If LO<HI
K=ARRAY(LO) : L=LO : H=HI
While L<>H
While H>L and K<=ARRAY(H)
Dec H
Wend
Swap ARRAY(L),ARRAY(H)
While L<H and K=>ARRAY(L)
Inc L
Wend
Swap ARRAY(L),ARRAY(H)
Wend
QUICKSORT[LO,L-1]
QUICKSORT[H+1,HI]
End If
End Proc
'
Procedure BUBBLE[LO,HI]
Shared ARRAY()
For J=HI-1 To LO Step -1
For I=LO To J
If ARRAY(I)>ARRAY(I+1)
T=ARRAY(I) : ARRAY(I)=ARRAY(I+1) : ARRAY(I+1)=T
End If
Next
Next
End Proc