Skip to content

Instantly share code, notes, and snippets.

@shaunlgs
Created October 9, 2016 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlgs/8b2e31b232e49c4cafdb8b60a3af2f51 to your computer and use it in GitHub Desktop.
Save shaunlgs/8b2e31b232e49c4cafdb8b60a3af2f51 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <conio.h>
using namespace std;
void BubbleSort(int data[], int listSize)
{
int pass, tempValue;
for(pass = 1; pass < listSize; pass++)
{
for(int x=0; x < listSize - pass; x++)
{
if(data[x] > data[x+1])
{
tempValue = data[x];
data[x] = data[x+1];
data[x+1] = tempValue;
}
}
}
}
int main()
{
int data[15] = {9,10,3,5,1,2,8,4,3,8,10,3,23,1,7};
cout << "Before bubble sort:" << endl;
for(int i=0; i<15; i++)
{
cout << data[i] << " ";
}
cout << endl;
BubbleSort(data, 15);
cout << "After bubble sort:" << endl;
for(int i=0; i<15; i++)
{
cout << data[i] << " ";
}
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment