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

Username:   Password: 
 RegisterRegister   
 How to put numbers in order?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
we64




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




PostPosted: Tue Jan 27, 2004 10:14 pm   Post subject: (No subject)

Find their ASCII values and use an if statement.
AsianSensation




PostPosted: Tue Jan 27, 2004 10:29 pm   Post subject: (No subject)

store it in an array, then sort it.
Dan




PostPosted: Tue Jan 27, 2004 10:50 pm   Post subject: (No 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
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
we64




PostPosted: Tue Jan 27, 2004 11:12 pm   Post subject: (No subject)

Thanks guys, I made my works.
Cervantes




PostPosted: Wed Jan 28, 2004 8:52 am   Post subject: (No subject)

ascii values and an if statement? hmmmm.. I must try this,
I've always used arrays, seems the easiest way
Delos




PostPosted: Wed Jan 28, 2004 10:47 am   Post subject: (No 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.
McKenzie




PostPosted: Wed Jan 28, 2004 11:30 am   Post subject: (No 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.


quickSort.t
 Description:

Download
 Filename:  quickSort.t
 Filesize:  1.3 KB
 Downloaded:  252 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Jan 28, 2004 12:59 pm   Post subject: (No 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!
we64




PostPosted: Wed Jan 28, 2004 1:40 pm   Post subject: (No subject)

oh my goodness, you guys are professional... I am just a newbe, a lot to learn...
FDisk87




PostPosted: Wed Jan 28, 2004 2:21 pm   Post subject: (No subject)

we64 wrote:
I am just a newbe, a lot to learn...
We were all newbies at one point, never stop learning Smile
sport




PostPosted: Wed Jan 28, 2004 2:51 pm   Post subject: (No 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
Paul




PostPosted: Thu Feb 05, 2004 12:44 pm   Post subject: (No 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
Cervantes




PostPosted: Thu Feb 05, 2004 5:11 pm   Post subject: (No 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 Razz). simple and effective, I like it Smile
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  [ 14 Posts ]
Jump to:   


Style:  
Search: