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

Username:   Password: 
 RegisterRegister   
 Bubble Sorting Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GoodbyeSoberDay1




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Tallguy




PostPosted: Thu Mar 27, 2008 7:28 am   Post subject: Re: Bubble Sorting Help

what do you mean by 'bubble sorting'?
fishtastic




PostPosted: 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
GoodbyeSoberDay1




PostPosted: Thu Mar 27, 2008 7:49 am   Post subject: (No 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]
Carey




PostPosted: 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.
GoodbyeSoberDay1




PostPosted: 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.
Nyrd




PostPosted: Thu Mar 27, 2008 9:09 am   Post subject: Re: Bubble Sorting Help

A swap would look something like this :

Turing:


var a :int := 4
var b :int := 2
var temp : int   %this is going to be a "holder" variable

temp := a %temp = 4
a := b       % a=2
b := temp  %b=4


%%Or alternatively, at a more advanced level . . .

var a :int := 4
var b:int := 2

a := a xor b
b := b xor a
a:= a xor b




The second more memory efficient as no third variable has to be declared. Though it only works on integers.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: