Sort Int Array

BlitzMax Forums/BlitzMax Programming/Sort Int Array

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).

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.

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.

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

klepto2: Thanks man!

Brucey ;-)

TaskMaster: nice and geeky :-D