[UCR]
[/\]

Universidad de Costa Rica
Escuela de Ciencias de la
Computación e Informática
[<=] [home] [<>] [\/] [=>]

BubbleSort()

   procedure swap ( var x, y: recordtype )
     { swap exchanges the values of x and y }
     var
         temp: recordtype;
     begin
       temp := x;
       x := y;
       y := temp
     end; { swap }


(1) for i := 1 to n-1 do
(2)      for j := n downto i+1 do
(3)           if A[j].key < A[j-1].key then
(4)                swap(A[j], A[j-1])
Aho, Alfred V.; Hopcroft, John E.; Ullman, Jefrrey D.
"Data Structures and Algorithms"; Addisson Wesley Publishing Co.; 1984.