Last active
April 21, 2017 19:25
-
-
Save ArtyomLazyan/6fb1988bbaa48344b941afe0303483d4 to your computer and use it in GitHub Desktop.
BubbleSort
This file contains 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
/* *************** 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