Skip to content

Instantly share code, notes, and snippets.

@aadimator
Created September 18, 2015 10:03
Show Gist options
  • Save aadimator/d16a1320205c48a46326 to your computer and use it in GitHub Desktop.
Save aadimator/d16a1320205c48a46326 to your computer and use it in GitHub Desktop.
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