-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathselect.c
46 lines (40 loc) · 876 Bytes
/
select.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
45
46
#include <stdio.h>
void selectsort (int x[], int n, int i);
void main()
{
int vetor[10],i,n;
printf("\nDigite a quantidade de vetores: ");
scanf("%d",&n);
printf("\nDigite os numeros: ");
for (i=0;i<n;i++)
{
scanf("%d",&vetor[i]);
}
selectsort(vetor,n,n-1);
printf("FICOU: \n");
for (i=0;i<n;i++)
{
printf("%d ",vetor[i]);
}
printf("\n\n");
}
void selectsort (int x[], int n, int i)
{
int indx, j, large;
if (i<=0)
return;
else{
/*coloca o maior elemento de x[0] até x[i] em large e seu indice em indx*/
large = x[0];
indx = 0;
for (j = 1; j <= i; j++){
if (x[j] > large) {
large = x[j];
indx = j;
}
}
x[indx] = x[i];
x[i] = large;
selectsort(x,n,i--);
}
}