Created
March 6, 2016 16:14
-
-
Save ninjapanzer/68eb6ba01c75bdd9009c to your computer and use it in GitHub Desktop.
Bubble Sort C++
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
| #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