Sort Int Array

BlitzMax Forums/BlitzMax Programming/Sort Int Array

Grey Alien(Posted 2007) [#1]
Hmm just did some searching (via google of this site) and can't find any handy BMAX routines to sort an array of integers. There's some bubble sorts for BBasic but not BMax. Looks like I'll have to make one then...shouldn't be too hard. Bubble is easy, but binary sort is faster...(well depends on the application).


klepto2(Posted 2007) [#2]
Strict

Local Array:Int[100]

For Local I:Int = 0 To 99
	Array[I] = Rand(0,1000)
Next


Array.Sort(True) 'True for Ascending

For Local I:Int = 0 To 99
	Print Array[I] 
Next



Arrays have already a sort method so no need to find or write another one.


Brucey(Posted 2007) [#3]
Bubble is easy, but binary sort is faster

Of course, you meant quick-sort and binary-search ;-)

The built-in array sort uses a quick-sort algorithm.


TaskMaster(Posted 2007) [#4]
Here is a great site for comparing sorting algo's... With java source examples, but that should be easy to change to BM...

http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html


Grey Alien(Posted 2007) [#5]
klepto2: Thanks man!

Brucey ;-)

TaskMaster: nice and geeky :-D