Computer Science Canada Bubble Sorting Help |
Author: | GoodbyeSoberDay1 [ Thu Mar 27, 2008 7:26 am ] |
Post subject: | Bubble Sorting Help |
Hi, If anyone could direct me to a good tutorial on how to do bubble sorting or explain to me how to do it that would be great. Thanks. |
Author: | Tallguy [ Thu Mar 27, 2008 7:28 am ] |
Post subject: | Re: Bubble Sorting Help |
what do you mean by 'bubble sorting'? |
Author: | fishtastic [ Thu Mar 27, 2008 7:42 am ] |
Post subject: | RE:Bubble Sorting Help |
wikipedia is always good. and so is google, it takes you to wikipedia http://en.wikipedia.org/wiki/Bubble_sort |
Author: | GoodbyeSoberDay1 [ Thu Mar 27, 2008 7:49 am ] |
Post subject: | |
In most of the pseudocode i found, it had a variable called swap.... what do I declare this variable as? procedure bubbleSort for j : 1 .. upper(text) - 1 const last := upper(text) - j + 1 for k : 1 .. last - 1 if text (k) > text (k + 1) then swap (text, k, k + 1) %What does the swap here do? Or what should I call it end if end for end for end bubbleSort [/syntax] |
Author: | Carey [ Thu Mar 27, 2008 8:02 am ] |
Post subject: | RE:Bubble Sorting Help |
judging by the code it looks like swap is a procedure that switches element k and k+1 in an array called text. |
Author: | GoodbyeSoberDay1 [ Thu Mar 27, 2008 8:13 am ] |
Post subject: | Re: RE:Bubble Sorting Help |
Carey @ Thu Mar 27, 2008 8:02 am wrote: judging by the code it looks like swap is a procedure that switches element k and k+1 in an array called text.
Yeah... That doesn't answer much. I meant something like would swap be another procedure or something. |
Author: | Nyrd [ Thu Mar 27, 2008 9:09 am ] | ||
Post subject: | Re: Bubble Sorting Help | ||
A swap would look something like this :
The second more memory efficient as no third variable has to be declared. Though it only works on integers. |