Skip to content

Instantly share code, notes, and snippets.

@ro0opf
Created April 1, 2019 14:14
Show Gist options
  • Save ro0opf/a8f007242a0edc648024c89d61621f60 to your computer and use it in GitHub Desktop.
Save ro0opf/a8f007242a0edc648024c89d61621f60 to your computer and use it in GitHub Desktop.
void selectionSort(int arr[], int n) {
int min_idx;
for (int i = 0; i < n - 1; i++) {
min_idx = i;
for (int j = i + 1; j < n; j++) {
res.compare = res.compare+1;
if (arr[j] < arr[min_idx]) {
min_idx = j;
}
}
swap(&arr[i], &arr[min_idx]);
res.move += 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment