-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_struct.c
36 lines (33 loc) · 855 Bytes
/
data_struct.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
#include "data_struct.h"
#include "utils.h"
List* list_new(int val)
{
List *li = (List*)malloc(sizeof(List));
li->val = val;
li->next = NULL;
return li;
}
void queue_push(Queue *que, int val)
{
if (que->back == NULL) {
que->front = que->back = list_new(val);
} else {
List *new_node = list_new(val);
que->back->next = new_node;
que->back = new_node;
}
}
int queue_pop(Queue *que)
{
if (que->front == NULL) {
return -1;
} else {
List *old = que->front;
que->front = que->front->next;
if (que->front == NULL)
que->back = NULL;
int ret = old->val;
free(old);
return ret;
}
}