Skip to content

Instantly share code, notes, and snippets.

@ArtyomLazyan
Last active April 21, 2017 19:25
Show Gist options
  • Save ArtyomLazyan/6fb1988bbaa48344b941afe0303483d4 to your computer and use it in GitHub Desktop.
Save ArtyomLazyan/6fb1988bbaa48344b941afe0303483d4 to your computer and use it in GitHub Desktop.
BubbleSort
/* *************** BUBBLE SORT speed O(n^2) ***************** */
#include <iostream>
int ar[] = { 5, 9, 21, 1, 34, 22, 8, 12, 0, 22, 90, 65 };
int size = sizeof(ar) / sizeof(ar[0]);
void bubbleSort(int arr[])
{
for (int i = 0; i < size - 1; i++)
{
for (int j = 0; j < size - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main()
{
bubbleSort(ar);
for (int i = 0; i < size; i++)
std::cout << ar[i] << " ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment