-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque_main.c
66 lines (57 loc) · 1.2 KB
/
deque_main.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
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "src/ed/deque.h"
typedef struct
{
int x, y;
} Celula;
Celula *celula_create(int x, int y)
{
Celula *c = malloc(sizeof(Celula));
c->x = x;
c->y = y;
return c;
}
void celula_free(Celula *c)
{
free(c);
}
void free_fn (void *cel) {
celula_free(cel);
}
int main()
{
int i, n, x, y;
char cmd[10];
Deque *d = deque_construct(free_fn);
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("\n%s", cmd);
if (!strcmp(cmd, "PUSH_BACK"))
{
scanf("%d %d", &x, &y);
deque_push_back(d, celula_create(x, y));
}
else if (!strcmp(cmd, "PUSH_FRONT"))
{
scanf("%d %d", &x, &y);
deque_push_front(d, celula_create(x, y));
}
else if (!strcmp(cmd, "POP_BACK"))
{
Celula *c = deque_pop_back(d);
printf("%d %d\n", c->x, c->y);
celula_free(c);
}
else if (!strcmp(cmd, "POP_FRONT"))
{
Celula *c = deque_pop_front(d);
printf("%d %d\n", c->x, c->y);
celula_free(c);
}
}
deque_destroy(d);
return 0;
}