Created
February 10, 2013 17:09
-
-
Save sprintr/4750246 to your computer and use it in GitHub Desktop.
The simplest bubble sorting example in cpp!!!
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
#include <iostream> | |
#include <cstdlib> | |
using namespace std; | |
int main() | |
{ | |
int list[]={9, 1, 4, 2, 8}; | |
int i, j; | |
for(i = 0; i < 5; i++) | |
{ | |
for(j = 0; j < i; j++) | |
{ | |
if(list[j] > list[j+1]) | |
{ | |
int temp = list[j]; | |
list[j] = list[j+1]; | |
list[j+1] = temp; | |
} | |
} | |
} | |
// display the list | |
for(int i = 0; i < 5; i++) | |
cout << list[i] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment