Restored from previous forum. Originally posted by Cantor.
Hello!
Is there a way to sort (quick sort or shell sort) the items
of an array (numerical or strings)?
Will there be a sort command implemented in future versions of PB?
Greetings,
Martin.
--
Best regards,
Martin
Sort command missing
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by wayne1.
; From pure basic examples/sources
; QuickSort example in PureBasic !
;
DefType.l
Dim a.l(10000)
Procedure QuickSort(g.l, d.l)
If g = v
ok = 0
Repeat
If j>0
j=j-1
Else
ok=1
EndIf
If a(j) 0
tmp.l = a(i)
a(i) = a(j)
a(j) = tmp
Until j <= i
t = a(j)
a(j) = a(i)
a(i) = a(d)
a(d) = t
QuickSort(g, i-1)
QuickSort(i+1, d)
EndIf
EndProcedure
a(10) = 1
a(20) = 256
a(100) = -200
a(1000) = -230
a(40) = -50
QuickSort(0,10000)
For k=0 To 5
MessageRequester("First elements", Str(a(k)), 0)
Next
For k=9999 To 10000
MessageRequester("Last elements", Str(a(k)), 0)
Next
End
Edited by - wayne1 on 17 August 2001 01:23:53
; From pure basic examples/sources
; QuickSort example in PureBasic !
;
DefType.l
Dim a.l(10000)
Procedure QuickSort(g.l, d.l)
If g = v
ok = 0
Repeat
If j>0
j=j-1
Else
ok=1
EndIf
If a(j) 0
tmp.l = a(i)
a(i) = a(j)
a(j) = tmp
Until j <= i
t = a(j)
a(j) = a(i)
a(i) = a(d)
a(d) = t
QuickSort(g, i-1)
QuickSort(i+1, d)
EndIf
EndProcedure
a(10) = 1
a(20) = 256
a(100) = -200
a(1000) = -230
a(40) = -50
QuickSort(0,10000)
For k=0 To 5
MessageRequester("First elements", Str(a(k)), 0)
Next
For k=9999 To 10000
MessageRequester("Last elements", Str(a(k)), 0)
Next
End
Edited by - wayne1 on 17 August 2001 01:23:53
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
. Seriously, I will add lighning fast sorting for Array (any type, from byte to floats including string). It's already present in the AmigaOS version.
Fred - AlphaSND
Of course it doesThanks a lot!
The procedure works well.
Greetings,
Martin.
--
Best regards,
Martin

Fred - AlphaSND