Modified the Graphics Portion to only redraw the swapped data
set window on
SET DISPLAY MODE 1024,768,32
set text font "verdana" rem "WESTMINSTER"
Set text size 16
SET TEXT OPAQUE
ink RGB(255,255,255),RGB(1,1,1)
color backdrop RGB(0,0,120)
sync off
sync rate 0
global N as integer
global L as Integer
cls
randomize timer()
set cursor 10,10
input "Enter Array Size to Sort : ", N
dim A(N) as integer
for L = 1 to N
A(L) = rnd(1024)
next L
set cursor 10,30
print "Sorting ",N," numbers..."
sync on
sync rate 0
DrawArray()
StartTime = timer()
QuickSort(1,N)
sync off
EndTime = Timer()-StartTime
DrawArray()
Set Cursor 10,50
Print "Time Taken ",Endtime, " Miliseconds"
wait key
Function QuickSort(L,R)
I as integer
J as integer
X as integer
W as integer
I = L
J = R
X = A((L+R)/2)
repeat
while A(I) < X
inc I
endwhile
while X < A(J)
dec J
endwhile
if I <= J
W = A(I)
A(I) = A(J)
A(J) = W
rem remark out or delete the next 2 line to disable graphics
rem 500 items take approx 5 seconds with graphic 1 or 2 miliseconds without
rem DrawLine(I)
rem Drawline(J)
I = I + 1
J = J - 1
endif
until I >= J
if L < J then QuickSort(L,J)
if I < R then QuickSort(I,R)
EndFunction
Function DrawLine(i)
rem lock pixels
ink Rgb(125,0,0),Rgb(0,0,0)
line 1,100+i,A(i),100+i
ink Rgb(0,0,0),Rgb(255,255,255)
line A(i),100+i,1024,100+i
rem unlock pixels
sync
endfunction
Function DrawArray()
box 0,100,1000,100+N,0,0,0,0
for i = 1 to N
DrawLine(i)
next i
sync
endfunction
Run Time reduced to 30% remove rem's to see sort take place
System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX