-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
118 lines (87 loc) · 1.93 KB
/
main.c
File metadata and controls
118 lines (87 loc) · 1.93 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdio.h>
#include <stdlib.h>
#include "ordvetor.h"
//Função base para a comparação dos ponteiros
int myCOMP(void* x, void* y){
int ptx = *((int*)x);
int pty = *((int*)y);
if(ptx - pty < 5){
return -1;
}else{
if(ptx - pty > 5) return 1;
else return 0;
}
}
//Função para imprimir a estrutura do vetor
void print(void** vet, int P){
int i;
printf("VETOR DE %d TAMANHO:\n", P);
for(i = 0; i < P; i++){
printf(" %d ", *((int*)vet[i]));
}
printf("\n");
}
int main(){
VETORORD* vet = VETORD_create(10, myCOMP);
int* x;
int i;
printf("INCLUINDO... \n");
for(i = 0; i < vet->N; i++){
x = malloc(sizeof(int));
*x = i*10;
VETORD_add(vet, x);
}
print(vet->elems, vet->P);
printf("REMOVENDO!");
VETORD_remove(vet);
print(vet->elems, vet->P);
return 0;
}
/*
#include <time.h>
int comparar(void* x, void* y) {
int intX = *((int*) x);
int intY = *((int*) y);
if (intX < intY) {
return 1;
} else if(intX == intY) {
return 0;
}
return -1;
}
int main() {
int VETOR_SIZE = 0;
printf("Digite o tamanho do vetor: ");
scanf("%d", &VETOR_SIZE);
VETORORD* vector = VETORD_create(VETOR_SIZE, comparar);
int numbers[VETOR_SIZE];
double time_spent = 0.0;
clock_t begin = clock();
//adicionar elementos
for (int i = 0; i < VETOR_SIZE; i++) {
int temp;
printf("Digite algo: ");
scanf("%d", &temp);
numbers[i] = temp;
VETORD_add(vector, &numbers[i]);
}
printf("VETOR ORIGINAL: ");
for (int i = 0; i < vector->P; i++) {
printf("%d - ", *((int*) vector->elems[i]));
}
printf("FIM\n");
remover elementos
for (int i = 0; i < 5; i++) {
VETORD_remove(vector);
}
printf("LISTA FINAL: ");
for (int i = 0; i < vector->P; i++) {
printf("%d - ", *((int*) vector->elems[i]));
}
printf("FIM\n");
clock_t end = clock();
time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
printf("\nTempo decorrido: %lf segundos!\n", time_spent);
return 0;
}
*/