Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created August 26, 2012 20:13
Show Gist options
  • Save fsouza/3483285 to your computer and use it in GitHub Desktop.
Save fsouza/3483285 to your computer and use it in GitHub Desktop.
#include <iostream>
void
selection(int v[], int size)
{
int pos, aux;
for(int i = 0; i < size; i++) {
pos = i;
for(int j = i+1; j < size; j++) {
if(v[j] < v[pos]) {
pos = j;
}
}
if(pos != i) {
aux = v[i];
v[i] = v[pos];
v[pos] = aux;
}
}
}
int
main(void)
{
int v[] = {5, 4, 2, 10, 30, 8};
selection(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