-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht_queue_list.c
More file actions
50 lines (45 loc) · 1.01 KB
/
t_queue_list.c
File metadata and controls
50 lines (45 loc) · 1.01 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
#include <stdio.h>
#include <stdlib.h>
#include "t_cell.h"
#include "t_queue_list.h"
t_queue_list createEmptyQueue() {
t_queue_list q;
q.head = NULL;
q.tail = NULL;
return q;
}
int isEmptyQueue(t_queue_list ql) {
return ql.head == NULL;
}
void enqueue(t_queue_list *ql, int val) {
t_cell *nouv = CreateCell(val);
if (isEmptyQueue(*ql)) {
ql->head = nouv;
ql->tail = nouv;
} else {
ql->tail->next = nouv;
ql->tail = nouv;
}
}
int dequeue(t_queue_list *ql) {
if (isEmptyQueue(*ql)) {
return -1; // Indiquer que la file est vide
}
t_cell *temp = ql->head;
int val = temp->value;
ql->head = ql->head->next;
if (ql->head == NULL) {
ql->tail = NULL;
}
free(temp);
return val;
}
void displayQueue(t_queue_list ql) {
t_cell *cur = ql.head;
printf("[ ");
while (cur != NULL) {
printf("%d ", cur->value);
cur = cur->next;
}
printf("]");
}