Created
October 9, 2016 03:08
-
-
Save shaunlgs/8b2e31b232e49c4cafdb8b60a3af2f51 to your computer and use it in GitHub Desktop.
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 <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