{ 
  * shuffle sort * 
  
  Author: David Benn
    Date: 29th March 1992
}

defint a-z

dim n(500),s(500)

maxval=499

true=-1
false=0

'...fill array with random numbers
randomize timer
for i=0 to maxval
 n(i)=int(rnd*1000)
next

print "sorting";maxval+1;"values with a shuffle sort."
time0!=timer

'...shuffle sort
top=0

for i=0 to maxval
 x=n(i)

 locating=true
 c=0
 
 '...find correct spot
 while locating and c<top
  if x < s(c) then
    locating=false
  else
    c=c+1
  end if
 wend

 { make a gap for the new number
   or just add it to the list }
 if c<top then
   '...shuffle
   for j=top to c+1 step -1
     s(j)=s(j-1)
   next
 end if

 '...insert new item
 s(c)=x
 top=top+1

next

time1!=timer
print "time elapsed (shuffle):";time1!-time0!;"seconds."
