Created
September 18, 2015 10:03
-
-
Save aadimator/d16a1320205c48a46326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubble_sort(int Array[], int size) | |
{ | |
bool sorted = false; // assume that the array is not sorted | |
while (!sorted) | |
{ | |
bool swaped = false; | |
for (int i = 0; i < size; i++) | |
{ | |
if (Array[i] > Array[i+1]) | |
{ | |
//------swap---------- | |
const int temp = Array[i]; | |
Array[i] = Array[i+1]; | |
Array[i+1] = temp; | |
//------swap---------- | |
swaped = true; | |
} | |
} | |
if (!swaped) sorted = true; // if there was no swapping then it means that the array is sorted | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment