It is currently Wed May 22, 2013 8:14 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject:
PostPosted: Thu Aug 16, 2001 11:05 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2001 12:21 am 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2001 12:24 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by Cantor.

Thanks a lot!

The procedure works well.

Greetings,
Martin.

--
Best regards,
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2001 7:39 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by fred.

Quote:
Thanks a lot!

The procedure works well.

Greetings,
Martin.

--
Best regards,
Martin


Of course it does :wink:. 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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: ozzie, Shield and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye