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

Username:   Password: 
 RegisterRegister   
 Bubble sort for Cards problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
addie1125




PostPosted: Thu Jan 15, 2009 9:55 am   Post subject: Bubble sort for Cards problem

i m doing a Bubble sort for a card game
this is a part of the game
i need to sort 1-20 cards on my hand
i only have 1 hand
i think the thing i made is not working
can you help me ? THank you very much!!!! this is my final project in gr11 com sci

this is a procedure in a 'Class'

var hand : array 1 .. 20 of int % global variable in the class

procedure sort
var count : int := 0
var firstValue : int
var secondvalue : int


for c : 1 .. 20
loop
firstValue := hand(count + 1)
secondValue := hand(count + 2)

if firstValue > SecondValue then
hand(count + 1) := secondValue
hand(count + 2) := firstValue
end if

count := count + 1
exit when count > 20

end loop
end for

end sort
Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: Thu Jan 15, 2009 11:42 am   Post subject: RE:Bubble sort for Cards problem

Hello addie1125;

Watch the boundary conditions; it's a very important aspect of programming algorithms.

Play computer and run that loop through your head when c is 20

Watch the work variable initialization; it's a very important aspect of programing algorithms. Wink

Play computer and think about count while running through the second pass of the for ... end for.

Cheers
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  [ 2 Posts ]
Jump to:   


Style:  
Search: