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

Username:   Password: 
 RegisterRegister   
 Help with Arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lordoftheflies




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




PostPosted: Tue May 16, 2006 1:59 pm   Post subject: (No subject)

In order to output them in order, you need to sort them so they are in order... makes sense, right? Wink

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.
Cervantes




PostPosted: Tue May 16, 2006 5:53 pm   Post subject: (No 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
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: