Sorting values in an array.
Author |
Message |
Piro24
|
Posted: 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? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Prince Pwn
|
Posted: Mon Dec 04, 2006 7:03 pm Post subject: (No 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. |
|
|
|
|
 |
Piro24
|
Posted: Mon Dec 04, 2006 9:45 pm Post subject: (No subject) |
|
|
I wasn't asking how to create random numbers, sorry. Thats easy. I want to know how to sort those numbers. |
|
|
|
|
 |
Clayton

|
Posted: Mon Dec 04, 2006 9:53 pm Post subject: (No subject) |
|
|
He told you, look up different sorting methods, namely bubble, selection and insertion. |
|
|
|
|
 |
|
|