Algorithms/Sorting-bubble sort/c method 1

From Wikibooks, open books for an open world
Jump to: navigation, search
void bubblesort(int a[], int len)
{
    int i, j, tmp;
 
    for(i = 0; i < len; i++)
    {
        for(j = 0; j < len - 1 - i; j++)
	{
           if(a[j] > a[j + 1])
           {
	        tmp = a[j + 1];
		a[j + 1] = a[j];
		a[j] = tmp;
	    }
        }
     }
}