Skip to content

Instantly share code, notes, and snippets.

@jryebread
Created April 10, 2017 05:15
Show Gist options
  • Save jryebread/fba1d501c3e70368f39406733a68b17a to your computer and use it in GitHub Desktop.
Save jryebread/fba1d501c3e70368f39406733a68b17a to your computer and use it in GitHub Desktop.
#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