-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsectionSort.c
73 lines (69 loc) · 1.79 KB
/
insectionSort.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
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
#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
#define N 50
int opc, i, j, aux, p_max, A[N], x;
void insectionSort(){
for(j=1; j<N; j++){
aux=A[j];
i=j-1;
while(i>=0 && A[i]>aux){
A[i+1] = A[i];
i=i-1;
}
A[i+1] = aux;
}
}
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]);
}
insectionSort();
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]);
}
insectionSort();
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]);
}
insectionSort();
printf("\nVETOR ORDENADO\n");
for(i=0; i<N; i++)
{
printf("%d \n", A[i]);
}
break;
}
}
}
getch();
}