Computer Science Canada

Sorting values in an array.

Author:  Piro24 [ Mon Dec 04, 2006 6:17 pm ]
Post subject:  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?

Author:  Prince Pwn [ Mon Dec 04, 2006 7:03 pm ]
Post subject: 

To create the random numbers, do this:
code:

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.

Author:  Piro24 [ Mon Dec 04, 2006 9:45 pm ]
Post subject: 

I wasn't asking how to create random numbers, sorry. Thats easy. I want to know how to sort those numbers.

Author:  Clayton [ Mon Dec 04, 2006 9:53 pm ]
Post subject: 

He told you, look up different sorting methods, namely bubble, selection and insertion.


: