Follow

Translate

Friday, March 11, 2016

Bubble Sort

(Bubble Sort) BUBBLE(DATA, N)
Here DATA is an array with N elements. This algorithm sorts the elements in DATA.



1.   Repeat Steps 2 and 3 for K = 1 to N - 1.

2.   Set PTR : = 1.       [Initializes pass pointer PTR.]

3.     Repeat while PTR < N - K:    [Execute pass.]  // Less Than Equal

      (a)   If DATA[PTR]  > DATA[PTR + 1], then:
               Interchange DATA[PTR] and DATA[PTR + 1].
               [End of If Structure.]

     (b)  Set PTR : = PTR + 1.

           [End of inner Loop.]
     [End of Step 1 outer loop.]

4. Exit.
             

0 comments:

Post a Comment