Author |
Message |
Bro
|
Posted: Wed Dec 05, 2007 8:14 pm Post subject: Ordering numbers from greatest to least... help |
|
|
Hi I am new to this site and turing in General and I need some help with a program.
My teacher gave me a program to work on and he said that it has to ask the user to put in three numbers and the program will put them in order from greatest to least.sounds easy enough right? well he also said that it should also be able to ask th user for 300 numbers with only changing a few lines. Before he gave me a program something like this one and I took the time to write out each and every combination there was. He said there was an easier way. Can someone please help me. As i said i am new and only know the most basic techniques. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Wed Dec 05, 2007 8:16 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
Check into Arrays and the Bubble Sort. Arrays can be found in the Turing Walkthrough, and Bubble Sorts are all over [Turing Submissions], as well you can check out Wikipedia for examples there too. |
|
|
|
|
|
questionableninja
|
Posted: Thu Dec 06, 2007 8:12 am Post subject: Re: Ordering numbers from greatest to least... help |
|
|
var amnt, num : int
var rnum : real
var temp : string
loop
put "how many words do you want to enter"
get rnum
exit when (rnum = round (rnum) and (rnum > 0))
end loop
num := round (rnum)
var word : array 1 .. num of string
for munch : 1 .. num
put "Enter your word", munch
get word (munch)
cls
end for
for cc : 1 .. num
put word (cc)
end for
put ""
amnt := num
for xx : 1 .. (amnt - 1)
for yy : (xx + 1) .. amnt
if (word (xx) > word (yy)) then
temp := word (xx)
word (xx) := word (yy)
word (yy) := temp
end if
end for
end for
for cc : 1 .. num
put word (cc)
end for |
|
|
|
|
|
Euphoracle
|
Posted: Thu Dec 06, 2007 3:47 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
One does not simply post the answer; defeats the purpose of a "help" section. |
|
|
|
|
|
LaZ3R
|
Posted: Thu Dec 06, 2007 6:09 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
It's very simple to be honest. The larger number of entries however, the longer the computer will take because if you have 300 numbers, it will have to go through that for loop SEVERAL times as you will only be moving numbers up or down the list one at a time.
Search up bubble sorting and you'll find how to do it. |
|
|
|
|
|
Silent Avenger
|
Posted: Thu Dec 06, 2007 9:04 pm Post subject: Re: Ordering numbers from greatest to least... help |
|
|
If you really want to impress your teacher and get a definite A+ look in to the comb sort. It's hard to try and figure out but it can sort millions of things hundreds of times faster than the bubble sort. Also if you want something really simple and slow the sequential sort is good. |
|
|
|
|
|
rdrake
|
Posted: Thu Dec 06, 2007 9:48 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
I rather like quick sort, but watch out for already sorted arrays. Merge sort is nice, too. Both are relatively simple to implement. |
|
|
|
|
|
HeavenAgain
|
Posted: Thu Dec 06, 2007 9:53 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
well, bubble sort isnt TOO bad if you add a boolean to check on the 2nd loop.
what i recommand is hmmm Instertion sort
easy and decent..... no just easy 2 loops and boom |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rdrake
|
Posted: Thu Dec 06, 2007 10:05 pm Post subject: Re: RE:Ordering numbers from greatest to least... help |
|
|
HeavenAgain @ Thu Dec 06, 2007 9:53 pm wrote: well, bubble sort isnt TOO bad if you add a boolean to check on the 2nd loop.
what i recommand is hmmm Instertion sort
easy and decent..... no just easy 2 loops and boom Bubble sort is O(n^2), which is horrible. Something like merge sort is O(nlogn), which is a lot better. Try sorting 500k elements with bubble sort then merge sort and you'll know why I advise against it strongly. |
|
|
|
|
|
HeavenAgain
|
Posted: Thu Dec 06, 2007 10:14 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
on that note, what is the quickest sort? for not so big element, medium element, and large? and yea.. i know bubble sort is horrible... i dont like it as well poor thing, no one likes it, and its the first thing (mostly) everyone learns. |
|
|
|
|
|
Silent Avenger
|
|
|
|
|
Euphoracle
|
Posted: Thu Dec 06, 2007 11:18 pm Post subject: RE:Ordering numbers from greatest to least... help |
|
|
I think that's far too advanced for this topic. |
|
|
|
|
|
Silent Avenger
|
Posted: Fri Dec 07, 2007 12:05 am Post subject: Re: RE:Ordering numbers from greatest to least... help |
|
|
HeavenAgain @ Thu Dec 06, 2007 10:14 pm wrote: on that note, what is the quickest sort?
I guess I could have been clearer but I was answering HeavenAgain's question. |
|
|
|
|
|
Euphoracle
|
Posted: Fri Dec 07, 2007 1:48 am Post subject: RE:Ordering numbers from greatest to least... help |
|
|
Oh, sorry |
|
|
|
|
|
|