determine highest value

BlitzPlus Forums/BlitzPlus Programming/determine highest value

Paulo(Posted 2004) [#1]
How can I determine the highest value from 6 different INT's ? and it would also be nice to determine the difference between each value, eg, get the highest value from the 6 and get the difference between it and the other 5.

I can see how to do it with tons of IF's but I didnt think that was a nice way to do it.
Any help is very much appreciated.


soja(Posted 2004) [#2]
You can do it with a recursive function. It looks at the entire list, finds the smallest number, swaps it with the last position's number, then repeats with a list shortened by one, until it gets down to the last one, which shuld be the biggest number, at the top of the list.
; recursive sort
Dim sortlist(6)
For i = 1 To 6
	sortlist(i) = Rand(100)
	Print "Sortlist("+i+") = " + sortlist(i)
Next

sort(6)

Print "---"
For i = 1 To 6
	Print "Sortlist("+i+") = " + sortlist(i)
Next

Print "---"
For i = 1 To 6
	Print "Difference("+i+") = " + (sortlist(1) - sortlist(i))
Next
WaitKey

Function sort(depth)
	If depth = 1 Then Return
	low% = 1
	For i = 2 To depth
		If sortlist(i) < sortlist(low) Then low = i
	Next
	temp% = sortlist(depth)
	sortlist(depth) = sortlist(low)
	sortlist(low) = temp
	sort(depth - 1)
End Function



Paulo(Posted 2004) [#3]
Thank you soja. That's really cool of you. :)