
-----------------------------------
addie1125
Thu Jan 15, 2009 9:55 am

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

-----------------------------------
btiffin
Thu Jan 15, 2009 11:42 am

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
