Skip to content

Instantly share code, notes, and snippets.

@sprintr
Created February 10, 2013 17:09
Show Gist options
  • Save sprintr/4750246 to your computer and use it in GitHub Desktop.
Save sprintr/4750246 to your computer and use it in GitHub Desktop.
The simplest bubble sorting example in cpp!!!
#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