help needed on sort routines
Author |
Message |
Leiak
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
AsianSensation
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
McKenzie
![](http://www.wizards.com/global/images/swtcg_article_27_pic3_en.gif)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sun Jan 25, 2004 8:54 pm Post subject: (No subject) |
|
|
Good grief! Put that Java away! |
|
|
|
|
![](images/spacer.gif) |
shorthair
![](http://www.members.shaw.ca/rfolz/domo-kun.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
shorthair
![](http://www.members.shaw.ca/rfolz/domo-kun.jpg)
|
Posted: Sun Jan 25, 2004 9:23 pm Post subject: (No subject) |
|
|
Okay , i wsa just wondering how ou got java from his post , , but what is hte pointo f bubble sorting ? What does it do ? |
|
|
|
|
![](images/spacer.gif) |
Dan
![](http://wiki.compsci.ca/images/archive/3/3c/20100325043407!Danspic.gif)
|
Posted: 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! |
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
McKenzie
![](http://www.wizards.com/global/images/swtcg_article_27_pic3_en.gif)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: 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](images/smiles/icon_biggrin.gif) , 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. |
|
|
|
|
![](images/spacer.gif) |
|
|