
-----------------------------------
Piro24
Mon Dec 04, 2006 6:17 pm

Sorting values in an array.
-----------------------------------
Let's just say my array has 10 random values between 1 and 100. I have to find the top 4 values of that, and output them. How would I do that?

-----------------------------------
Prince Pwn
Mon Dec 04, 2006 7:03 pm


-----------------------------------
To create the random numbers, do this:

var maxNum : int := 10
var num : array 1 .. maxNum of int
for i : 1 .. maxNum
    num (i) := Rand.Int (1, 100)
    put num (i), " " ..
end for


If you mean the 4 largest numbers of the array, possibly look up on bubble sort, selection sort, and insertion sort.

-----------------------------------
Piro24
Mon Dec 04, 2006 9:45 pm


-----------------------------------
I wasn't asking how to create random numbers, sorry. Thats easy. I want to know how to sort those numbers.

-----------------------------------
Clayton
Mon Dec 04, 2006 9:53 pm


-----------------------------------
He told you, look up different sorting methods, namely bubble, selection and insertion.
