Skip to content

Instantly share code, notes, and snippets.

@ninjapanzer
Created March 6, 2016 16:14
Show Gist options
  • Select an option

  • Save ninjapanzer/68eb6ba01c75bdd9009c to your computer and use it in GitHub Desktop.

Select an option

Save ninjapanzer/68eb6ba01c75bdd9009c to your computer and use it in GitHub Desktop.
Bubble Sort C++
#include <iostream>
int main() {
const int SIZE = 10;
int unsorted[SIZE] = {5,3,8,4,1,2,9,6,0,7};
for (int i = 0 ; i < ( SIZE - 1 ); i++) {
for (int j = 0 ; j < SIZE - i - 1; j++) {
std::cout << unsorted[i] << " " << unsorted[j] << std::endl;
if (unsorted[j] > unsorted[j+1]){
int swap = unsorted[j];
unsorted[j] = unsorted[j+1];
unsorted[j+1] = swap;
}
}
}
for(int i = 0; i < SIZE; i++){
std::cout << unsorted[i] << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment