Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created August 26, 2012 20:38
Show Gist options
  • Save fsouza/3483446 to your computer and use it in GitHub Desktop.
Save fsouza/3483446 to your computer and use it in GitHub Desktop.
#include <iostream>
void
bubble(int v[], int size)
{
for(int i = size-1; i >= 1; i--) {
int aux;
for(int j = i; j >= 0; j--) {
if(v[i] < v[j]) {
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
}
int
main(void)
{
int v[] = {5, 4, 2, 10, 30, 8};
bubble(v, 6);
for(int i = 0; i < 6; i++) {
std::cout << v[i] << " ";
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment