-
Notifications
You must be signed in to change notification settings - Fork 0
/
metodo2.c
43 lines (31 loc) · 917 Bytes
/
metodo2.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
#include <stdio.h>
#include <stdlib.h>
int main(){
int length;
printf("Quantos numeros voce deseja ordenar? ");
scanf("%d", &length);
fflush(stdin);
int *ptr;
ptr = (int*)malloc(length*sizeof(int));
for(int i = 0; i < length; i++){
printf("\nInsira o %d numero: ", i);
scanf("%d", (ptr+(i*sizeof(int))));
fflush(stdin);
}
int counter = 0;
while(counter < length){
for(int j = 0; j < length-1; j++){
if(*(ptr+(j*sizeof(int))) > *(ptr+((j+1)*sizeof(int)))){
int aux = *(ptr+(j*sizeof(int)));
*(ptr+(j*sizeof(int))) = *(ptr+((j+1)*sizeof(int)));
*(ptr+((j+1)*sizeof(int))) = aux;
}
}
counter++;
}
printf("\nSorted: \n");
for(int i = 0; i < length; i++){
printf("%d, ", *(ptr+(i*sizeof(int))));
}
return 0;
}