Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sorting values in an array.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
Piro24




PostPosted: 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
Sponsor
sponsor
Prince Pwn




PostPosted: 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




PostPosted: 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




PostPosted: Mon Dec 04, 2006 9:53 pm   Post subject: (No subject)

He told you, look up different sorting methods, namely bubble, selection and insertion.
 
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: