Skip to content

Instantly share code, notes, and snippets.

@ahmedengu
Last active March 9, 2016 04:04
Show Gist options
  • Save ahmedengu/5e6c74519e3f3fcc1210 to your computer and use it in GitHub Desktop.
Save ahmedengu/5e6c74519e3f3fcc1210 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void selectionSort() {
int arr[] = {1,5,9,8,9,4,7,5,6,3,1,7};
int size=12;
int i, j, min;
for (i = 0; i < size-1; i++) {
min = i;
for (j = i + 1; j < size; j++)
if (arr[j] < arr[min])
min = j;
if (min != i) {
arr[i] += arr[min];
arr[min] = arr[i] - arr[min];
arr[i] -= arr[min];
}
}
for (int i = 0; i < size; i++) {
cout<<arr[i] <<((i==size-1)?"":" ,");
}}
int main() {
selectionSort();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment