-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.c
executable file
·44 lines (39 loc) · 931 Bytes
/
list.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
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
listNodeS *createListNode(int node)
{
listNodeS *listNode = (listNodeS*)malloc(sizeof(listNodeS));
listNode->node = node;
listNode->next = NULL;
return listNode;
}
queueS *createQueue(){
queueS *queue = (queueS*)malloc(sizeof(queueS));
queue->tail = NULL;
queue->head = NULL;
return queue;
}
void addListNode(listNodeS* nodeEdges, int node){
listNodeS* new = createListNode(node);
new->next = nodeEdges->next;
nodeEdges->next = new;
}
void enqueue(queueS* queue, int node){
listNodeS* newTail = createListNode(node);
if (queue->head == NULL){
queue->head = newTail;
queue->tail = newTail;
}
else{
queue->tail->next = newTail;
queue->tail = newTail;
}
}
int dequeue(queueS* queue){
int node = queue->head->node;
listNodeS* aux = queue->head;
queue->head = queue->head->next;
free(aux);
return node;
}