Contents

Precondition:  the function accepts an unsorted array and integer size that is the size of the array:

Post condition: Sorted array

void BubbleSort ( int size, int array[])
{
    int current = 0;
    bool sorted = false;

            while (( current < size)&&(sorted = = false))
            {
                int walker = size-1;
                sorted = true;

                        while (walker > current)
                        {
                              if ( array[walker] < array[walker - 1] )
                                {
                                    sorted = false;
                                    exchange( array, walker, walker-1);
                                }
                      walker--;
                     }
                current++;
            }
}

Contents