Bubble Sort

Code Id 17
Date Updated 3/7/2010
Title Bubble sort  
Description
This is a type of sort where we pass through the table sequentially several times. Each pass puts the largest unsorted element into its right position by comparing each element in the table with its successor and interchanging the two elements if they are not in the proper order. 
                                  
Codes Snippet
bubble(int a[], int n)
{
        int i,j, temp;
        int swapped=TRUE;
        i=0;
        while(i < n- i � 1)
                {       if a[j]>a[j+1]
                {/*Interchange elements if they are out of order & set swapped to true*/
                                swapped = TRUE;
                                temp = a[j];
                                a[j] = a[j+1];
                        a[j+1] = temp;
                }/*end if */
                        j++; }/*End inner loop*/
                i++; }/*End of outer loop*/
}/*end of routine*/

Comments are closed.