Rearranging numbers in order

BlitzMax Forums/BlitzMax Programming/Rearranging numbers in order

Tobo(Posted 2007) [#1]
Hello, folks.

Say I had a list of 10 random numbers in an array. How do I put them in order?

Many thanks.

T.


degac(Posted 2007) [#2]
Local ARRAY:Int[10]

For Local i:Int=0 Until 10
	array[i]=Rand(1,100)
Next
For Local as:Int=EachIn array
	Print as
Next
array.sort
Print "Ordered..."
For as=EachIn array
	Print as
Next



Tobo(Posted 2007) [#3]
Thanks, but I was trying to understand the concept behind it.

Say the ARRAY.SORT command thing didn't exist - how would you code it then?

T


Yan(Posted 2007) [#4]
http://en.wikipedia.org/wiki/Sorting_algorithm


ImaginaryHuman(Posted 2007) [#5]
Yah, look up sorting algorithms. A simple sort is a bubble sort but it is slow, something like a quicksort is better.


Tobo(Posted 2007) [#6]
Fantastic article.

Just what I needed to know.

Thank you, all.

T


TaskMaster(Posted 2007) [#7]
Here is a link to some sorting algorithms. They are in java, but easy to convert to BMax. Each has an example on th epage that shows how it works.

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