Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
How to put numbers in order?
Author Message
we64

Posted: 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

Neja

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

Find their ASCII values and use an if statement.
AsianSensation

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

store it in an array, then sort it.
Dan

Posted: 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

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

Thanks guys, I made my works.
Cervantes

Posted: 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

Posted: 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

Posted: 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:  284 Time(s)

Sponsor
Sponsor

Delos

Posted: 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

Posted: 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

Posted: 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
sport

Posted: 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

Posted: 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

Posted: 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 ). simple and effective, I like it
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 14 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: