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

Username:   Password: 
 RegisterRegister   
 help needed on sort routines
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Leiak




PostPosted: Sun Jan 25, 2004 5:47 pm   Post subject: help needed on sort routines

i am doing a grade 11 compsci exam tomorrow and i know everything fine except im a lil in the dark on the sort routines i know its like

for x : 1..100
for y:1..100-x or something likethat then u set em all to equal each other but im not 100% sure any help is appreciated
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Sun Jan 25, 2004 5:48 pm   Post subject: (No subject)

bubble sort:

code:
for x : 1 .. 99
    for y : x + 1 .. 100

    end for
end for
McKenzie




PostPosted: Sun Jan 25, 2004 7:54 pm   Post subject: (No subject)

google "bubble sort" ==
code:
for (i=0; i<n-1; i++) {
  for (j=0; j<n-1-i; j++)
    if (a[j+1] < a[j]) {  /* compare the two neighbors */
      tmp = a[j];         /* swap a[j] and a[j+1]      */
      a[j] = a[j+1];
      a[j+1] = tmp;
  }
}


I know it's in C, but ... give it a look
Delos




PostPosted: Sun Jan 25, 2004 8:54 pm   Post subject: (No subject)

Good grief! Put that Java away!
shorthair




PostPosted: Sun Jan 25, 2004 9:07 pm   Post subject: (No subject)

Quote:

McKenzie Wrote , "i know its in C but.."


Quote:

Delos Wrote , "good grief put that java away"


Am i missing somthing
Delos




PostPosted: Sun Jan 25, 2004 9:16 pm   Post subject: (No subject)

shorthair wrote:
Quote:

McKenzie Wrote , "i know its in C but.."


Quote:

Delos Wrote , "good grief put that java away"


Am i missing somthing


My bad...didn't read properly.

But it looks like JAVA! Argggghhhh.

Seriously, the whole curly brackets and double + thing and all. Yes, I am aware of those being industry standard. Sorta.
shorthair




PostPosted: Sun Jan 25, 2004 9:23 pm   Post subject: (No subject)

Okay , i wsa just wondering how ou got java from his post , Very Happy Very Happy , but what is hte pointo f bubble sorting ? What does it do ?
Dan




PostPosted: Sun Jan 25, 2004 10:25 pm   Post subject: (No subject)

well techaly there is almost no difencte between the code in java and the code in c or c++ for that.

also you left out a break there for the if....
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
McKenzie




PostPosted: Sun Jan 25, 2004 10:35 pm   Post subject: (No subject)

McKenzie wrote:
google "bubble sort" ==

The point I was making is don't be afraid to jump on google to find code. If I were to type it myself I wouldn't use C in a Turing forum. I invested a whole 10 seconds finding the code. As far as the break goes the basic version of the bubble sort doesn't have it.
Delos




PostPosted: Mon Jan 26, 2004 10:22 am   Post subject: (No subject)

shorthair wrote:
Okay , i wsa just wondering how ou got java from his post , Very Happy Very Happy , but what is hte pointo f bubble sorting ? What does it do ?


Bubble sort...bubble sort.

How do I scoff thee?

Anyhow, bubble sorts are almost entirely deprecated. i.e., you would never use one to sort a list of more than 2 elements.

What they do is compare adjacent elements, and if the first is greater than the second, it switches them. It keeps doing this until the list is completely sorted.

Eg.

3 4 1 8 4 6
3 4 1 4 8 6
3 1 4 4 6 8
1 3 4 4 6 8

That may seem odd, the way it switches, but that's about how it works.

For a short list, no problem. For the average list that one would need sorted...it is sloooooooow.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: