Thursday, January 8, 2009

C code for bubble sort

#include <iostream.h>



int main()

{

        int a[6] = {5,19,11,18,27,22};

        int j;

        for(j=4;j>=0;j--)

                for(int i=0;i<=j;i++)

                {

                        if(a[i] < a[i+1])

                        {

                                int tmp = a[i];

                                a[i] = a[i+1];

                                a[i+1] = tmp;

                        }

                }

        for(j=0;j<6;j++)

                cout << a[j] << " " ;

        cout << endl;

}

No comments:

Blog Archive