Computer Science Canada How to put numbers in order?

 Author: we64 [ Tue Jan 27, 2004 9:50 pm ] Post subject: How to put numbers in order? If I have values like 5,1,15,12,54,34,23,35, how to put them from smallest to largest?

 Author: Neja [ Tue Jan 27, 2004 10:14 pm ] Post subject: Find their ASCII values and use an if statement.

 Author: AsianSensation [ Tue Jan 27, 2004 10:29 pm ] Post subject: store it in an array, then sort it.

 Author: Dan [ Tue Jan 27, 2004 10:50 pm ] Post subject: if u use that search thing on the top of the site u could have found a post such as this: http://www.compsci.ca/v2/viewtopic.php?t=447&highlight=sorting

 Author: we64 [ Tue Jan 27, 2004 11:12 pm ] Post subject: Thanks guys, I made my works.

 Author: Cervantes [ Wed Jan 28, 2004 8:52 am ] Post subject: ascii values and an if statement? hmmmm.. I must try this, I've always used arrays, seems the easiest way

 Author: Delos [ Wed Jan 28, 2004 10:47 am ] Post subject: Ah, sorting. How we all love thee? I guess bubble-sort is best for beginners...though it is so slow! Has anyone been able to implement a quick-sort in Turing? I was thinking of trying out some time.

 Author: McKenzie [ Wed Jan 28, 2004 11:30 am ] Post subject: It's more than just a beginner vs advanced debate. First you must determine the need for speed. Is the array being sorted each time you refresh your screen ? (very high need) or is it just when you check your high score list (very low need). On top of that you have to look at the size of the array that it will be used on. Although bubble sort is of order O(n^2) and quicksort is O(n Log(n)) there is a lot of overhead in quicksort making it slower on small samples (<20). Here is quicksort for those who want to compare.

 Author: Delos [ Wed Jan 28, 2004 12:59 pm ] Post subject: Ah yes...wonderful speeds. Now, consider this. Speed is just one factor. I have made a number of sorts, some more complex than others. One of them can sort 90000 random ints in less than 1 second. The other could do the same in about 30 seconds. However, if the values are changed around a bit, the first will sort 5000 ints in 29 seconds, and the second in 2 seconds. Why? Memory usage (and of course algorithm). Quick Sort is great because it uses little memory, and is fast - "Divide and Conquer". Bubble is slow, but uses very little memory. The average Dump Sort is lightning fast, but can use in the vicinity of 50 MB just to sort 5000 numbers. I guess in today's dog-sized memory-laden computer world, RAM is no problem. But getting into and searching through that RAM could be. Bubble sort is intuitive. Thus it can be labelled "beginner". Quick Sort is heavy on the maths and logic - not necassarily "advanced" - just 'more know-how needed'. Ah, sorting is so much fun. Every tried to sort strings!? Oh man...took me about 2 weeks to perfect an algorithm for those! Meh!

 Author: we64 [ Wed Jan 28, 2004 1:40 pm ] Post subject: oh my goodness, you guys are professional... I am just a newbe, a lot to learn...

 Author: FDisk87 [ Wed Jan 28, 2004 2:21 pm ] Post subject: we64 wrote:I am just a newbe, a lot to learn... We were all newbies at one point, never stop learning

Author:  sport [ Wed Jan 28, 2004 2:51 pm ]
Post subject:

Here is a sample of sort
 code: var num : array 1 .. 15 of int := init (1, 10, 55, 2, 3, 4, 6, 21, 431, 45, 646, 64, 6136, 161, 5) var temp : int var change : boolean loop     change := false     for i : 1 .. upper (num) - 1 % or 15-1         if num (i) > num (i + 1) then             temp := num (i)             num (i) := num (i + 1)             num (i + 1) := temp             change := true         end if     end for     exit when change = false end loop for i : 1 .. upper (num)     put num (i) end for

Author:  Paul [ Thu Feb 05, 2004 12:44 pm ]
Post subject:

I learned a new way of sorting oday:
 code: var num : array 1 .. 10 of int := init (6, 5, 4, 10, 85, 4, 6, 2, 11, 45) var numlist : array 1 .. 10 of int for a : 1 .. 10     put num (a), " " .. end for for a : 1 .. 10     var smallest := 1000     var where : int     for b : 1 .. 10         if num (b) < smallest then             smallest := num (b)             where := b         end if     end for     numlist (a) := smallest     num (where) := 1000 end for put "" for z : 1 .. 10     put numlist (z), " " .. end for

 Author: Cervantes [ Thu Feb 05, 2004 5:11 pm ] Post subject: my mom got this Turing tutorial book in an old book give away dealie and that's the way it does it in there. its a fairly easy way of sorting (coinsedently [haha sp], the only way I know ). simple and effective, I like it

 :