-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_sort.c
44 lines (40 loc) · 993 Bytes
/
select_sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
void sort(int total);
int main(){
int time;
scanf("%d", &time);
for(int count = 0; count < time; count++){
int total;
scanf(" %d", &total);
sort(total);
}
return 0;
}
void sort(int total){
int * nums = (int *) malloc(total * sizeof(int));
for(int count = 0; count < total; count++){
scanf(" %d", (nums + count));
}
int time = 0;
int min = *(nums + time);
int pos = time;
while(time < total - 1){
for(int count = time; count < total; count++){
if(*(nums + count) < min){
min = *(nums + count);
pos = count;
}
}
*(nums + pos) = *(nums + time);
*(nums + time) = min;
time++;
min = *(nums + time);
pos = time;
for(int count = 0; count < total; count++){
printf("%d ", *(nums + count));
}
putchar('\n');
}
free(nums);
}