Sunday, January 15, 2012

BubbleSort Pseudocode

---------------------------------------------------------------------------

PROGRAM BubbleSort:

/*===================
DECLARING VARIABLES
===================*/

int ARRAY[N];
int innerloop = 0;
int outerloop = 0;

/*-------------------*/

WHILE (outerloop < N)

    DO WHILE (innerloop < N)

        DO  IF (A[innerloop] > A[innerloop + 1])

                THEN Swap (A[innerloop], A[innerloop + 1]);

            END IF;

            innerloop++;

        END WHILE;

        innerloop = 0;

        outerloop++;

END WHILE;

/*-------------------*/

END.


---------------------------------------------------------------------------
---------------------------------------------------------------------------


PROGRAM Swap (int First, int Second):

/*===================
DECLARING VARIABLES
===================*/

int Temp;

/*-------------------*/
Temp = First;
First = Second;
Second = Temp;

END.

---------------------------------------------------------------------------

No comments:

Post a Comment