-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionSort.c
More file actions
48 lines (44 loc) · 745 Bytes
/
selectionSort.c
File metadata and controls
48 lines (44 loc) · 745 Bytes
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
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void print(int v[],int n){
printf("[");
for(int i=0;i<n;i++){
printf("%d",v[i]);
if(i<n-1){
printf(",");
}
}
printf("](%d)\n",n);
}
int max(int v[],int n){
int m=0;
for(int i=1;i<n;i++){
if(v[i]>v[m]){
m=i;
}
}
return m;
}
void selectionRec(int v[],int n){
int m,aux;
if(n<2){
return;
}
m = max(v,n);
aux = v[m];
v[m] = v[n-1];
v[n-1]=aux;
print(v,n);
selectionRec(v,n-1);
}
void selectionIt(int v[],int n){
int m,aux;
while(n>1){
m = max(v,n);
aux = v[m];
v[m] = v[n-1];
v[n-1]=aux;
n--;
}
}