-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.c
More file actions
76 lines (72 loc) · 1.87 KB
/
SelectionSort.c
File metadata and controls
76 lines (72 loc) · 1.87 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
#define N 50
int opc, i, j, aux, p_max, A[N], x;
int selectionSort(){
for(i=N; i>1; i--){
p_max=0;
for(j=1; j<i; j++){
if(A[j] > A[p_max]){
p_max=j;
}
aux = A[i-1];
A[i-1] = A[p_max];
A[p_max] = aux;
}
}
return p_max;
}
int main(){
printf("******MENU******\n\nMetodo de entrada da ARRAY:\n1- Ja Ordenado\n2- Aleatorio\n3- Ordem Inversa\n4- Exit\n\nOpcao: ");
scanf("%d", &opc);
while(opc != 4)
{
switch(opc)
{
case 1:{
printf("\nVETOR DADO\n");
for(i=0; i<N; i++){
A[i] = i;
printf("%d \n", A[i]);
}
selectionSort();
printf("\nVETOR ORDENADO\n");
for(i=0; i<N; i++){
printf("%d \n", A[i]);
}
break;
}
case 2:{
printf("\nVETOR DADO\n");
for(i=0; i<N; i++){
A[i] = rand() % 100;
printf("%d \n", A[i]);
}
selectionSort();
printf("\nVETOR ORDENADO\n");
for(i=0; i<N; i++){
printf("%d \n", A[i]);
}
break;
}
case 3:{
x = N;
printf("\nVETOR DADO\n");
for(i=0; i<N; i++){
A[i] = x;
x--;
printf("%d \n", A[i]);
}
selectionSort();
printf("\nVETOR ORDENADO\n");
for(i=0; i<N; i++)
{
printf("%d \n", A[i]);
}
break;
}
}
}
getch();
}