Computer Science Canada Help with Arrays |
| Author: | lordoftheflies [ Tue May 16, 2006 1:27 pm ] |
| Post subject: | Help with Arrays |
I have this problem with arrays. I've gotten the first part, where I can input numbers and it outputs the same set, and I've even figured out how to make the smallest number in the set of numbers. But I need it to display the numbers in order, from least to greatest. var number : array 1 .. 10 of int var small : int put "Input number" for i : 1 .. 10 get number (i) end for small := number (1) put "Smallest number" for i : 2 .. 10 if small > number (i) then small := number (i) end if end for put small that's what I have so far... thanks |
|
| Author: | TheOneTrueGod [ Tue May 16, 2006 1:59 pm ] |
| Post subject: | |
In order to output them in order, you need to sort them so they are in order... makes sense, right? There is a bubble sort procedure here: http://www.compsci.ca/v2/viewtopic.php?t=12268 but DON'T COPY IT DIRECTLY doing so is plagarism, and is subject to things as severe as expulsion in some schools. Instead, read the code, and learn from it. Create your own procedure that will do the same thing using the concept. Once you learn this, it is an easy matter to create your own. Good luck. |
|
| Author: | Cervantes [ Tue May 16, 2006 5:53 pm ] |
| Post subject: | |
Another good post to refer to: http://www.compsci.ca/v2/viewtopic.php?t=4091 That post contains terrific code, but it might be a little hard to understand what's going on just from the code. Perhaps some sort of detailed explanation of the concept, and some visuals would help? Try Wikipedia's Sorting Algorithm page. Scroll down a bit to the Summaries of some popular sorting algorithms. Try following the link to the full page about that type of sort. The Quicksort page, for example, has some nice visuals. Quicksort ![]() |
|