Codesnipp.it Social Code Sharing

Thang Do

Bubble Sorting

by Thang Do on Oct 19, 2011

//********************************************************************* //Function Type //********************************************************************* void bubbleSort(int arr[]) { bool swapped = true; int j = 0; int temp; while (swapped) { swapped = false; j++; for (int i = 0; i < n - j; i++) { if (arr[i] > arr[i + 1]) { tmp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = tmp; swapped = true; } } } } //********************************************************************* //********************************************************************* //Simple Loop Type //********************************************************************* for (int i = length-1; i >= 0; i--) { for (int x = 0; x < length; x++) { if (array[x] > array[x+1]) { int temp = array[x+1]; array[x+1] = array[x]; array[x] = temp; } } } //*********************************************************************

Can't see the comments? Please login first :)