Bubble sort for Cards problem
Author |
Message |
addie1125
![](http://compsci.ca/v3/uploads/user_avatars/48018503848127aef24586.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
btiffin
![](http://compsci.ca/v3/uploads/user_avatars/189169540547b535e50e4a7.jpg)
|
Posted: 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.
Play computer and think about count while running through the second pass of the for ... end for.
Cheers |
|
|
|
|
![](images/spacer.gif) |
|
|