Code: Select all
; Conversion of a BB sourcecode example
; Done by Andre ([url]mailto:andre@purebasic.com[/url])
; 06. April 2003
;- Init section
max=10000
Dim feld(max)
Dim speed(1,10)
;- Functions
Procedure quicksort(s,e)
i=s
j=e
Repeat
a = i+j
While feld(i) feld(a/2)
j = j-1
Wend
If i j
If j > s : quicksort(s,j) : EndIf
If i feld(j)
tmp = feld(i)
feld(i) = feld(j)
feld(j) = tmp
EndIf
Next
Next
EndProcedure
;- Start output
OpenConsole()
PrintN("Now Quicksort begins...")
;- Quicksort use
For t=1 To 10
For i=0 To max
feld(i)=Random(max)
Next
t1=gettickcount_() ; Windows API call to millisecs since system start
quicksort(0,1000*t)
t2=gettickcount_()
speed(0,t)=t2-t1
Next
PrintN("Quicksort finished.")
PrintN("Now Bubblesort begins...")
;- Bubblesort use
For t=1 To 10
For i=0 To max
feld(i)=Random(max)
Next
t1=gettickcount_()
bubblesort(0,1000*t)
t2=gettickcount_()
speed(1,t)=t2-t1
Next
PrintN("Bubblesort finished.")
PrintN("")
Print("Press Return to show results....")
Input()
ClearConsole()
;- Show results
ConsoleLocate(1,1)
Print("Lines")
ConsoleLocate(15,1)
Print("Quick [ms]")
ConsoleLocate(30,1)
Print ("Bubble [ms]")
For i=1 To 10
ConsoleColor(7,0)
ConsoleLocate(1,i+1)
Print(Str(i*1000))
ConsoleColor(14,0)
ConsoleLocate(15,i+1)
Print(Str(speed(0,i)))
ConsoleColor(11,0)
ConsoleLocate(30,i+1)
Print(Str(speed(1,i)))
Next
PrintN("") : PrintN("")
ConsoleColor(7,0)
Print("Press return to exit...")
Input()
CloseConsole()
End
André
*** German PureBasic Support ***