#include <stdio.h>
void selection_sort(int *a, int size) {
int i, j, min, minat;
for (i = 0; i < size; i++) {
min = a[i];
minat = i;
for (j = i + 1; j < size; j++) {
if (min > a[j]) {
min = a[j];
minat = j;
}
}
int temp = a[i];
a[i] = a[minat];
a[minat] = temp;
}
}
void print(int *a, int size) {
int i;
for (i = 0; i < size - 1; i++) {
printf("%d - ", a[i]);
}
printf("%d\n", a[i]);
}
int main() {
int size = 10;
int a[] = {9,6,5,23,2,6,2,7,1,8};
print(a, size);
selection_sort(a, size);
print(a, size);
return 1;
}
Title:
Selection Sort Dev-Cpp
Description:
#include <stdio.h> void selection_sort(int *a, int size) { int i, j, min, minat; for (i = 0; i < size; i++) { m...
...
Rating:
4