Created
April 10, 2017 05:15
-
-
Save jryebread/fba1d501c3e70368f39406733a68b17a to your computer and use it in GitHub Desktop.
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> | |
void bubbleSort(int *myarray, int length); | |
int main() | |
{ | |
int myarray[10] = { 1,2,7,9,8,6,4,5,4,3}; | |
bubbleSort(myarray, 10); | |
for (int x = 0; x < 10; x++) | |
std::cout << myarray[x] << std::endl; | |
return 0; | |
} | |
void bubbleSort(int *myarray, int length)//Bubble sort function | |
{ | |
int i, j; | |
for (i = 0; i<10; i++) | |
{ | |
for (j = 0; j<i; j++) | |
{ | |
if (myarray[i]>myarray[j]) | |
{ | |
int temp = myarray[i]; //swap | |
myarray[i] = myarray[j]; | |
myarray[j] = temp; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment