-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
72 lines (61 loc) · 1.43 KB
/
Copy pathqueue.c
File metadata and controls
72 lines (61 loc) · 1.43 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
/*-----------------------------------------------------------------*/
/*
Licence Informatique - Structures de données
Mathias Paulin (Mathias.Paulin@irit.fr)
Implantation du TAD Queue étudié en cours.
*/
/*-----------------------------------------------------------------*/
#include "queue.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "sha256.h"
/* Full definition of the queue structure */
typedef struct s_internalQueue {
char value[SHA256_BLOCK_SIZE*2+1];
struct s_internalQueue *next;
} InternalQueue;
struct s_queue {
InternalQueue *top;
int size;
};
Queue *createQueue() {
Queue *q = malloc(sizeof(Queue));
q->top = NULL;
q->size = 0;
return (q);
}
void deleteQueue(ptrQueue *q) {
InternalQueue *toDelete = (*q)->top;
while (toDelete) {
InternalQueue *f = toDelete;
toDelete = toDelete->next;
free(f);
}
free(*q);
*q = NULL;
}
Queue *queuePush(Queue *q, char *v) {
InternalQueue *new = malloc(sizeof(InternalQueue));
strcpy(new->value,v);
new->next = q->top;
q->top = new;
++(q->size);
return (q);
}
Queue *queuePop(Queue *q) {
assert (!queueEmpty(q));
q->top = q->top->next;
q->size--;
return (q);
}
char *queueTop(Queue *q) {
assert (!queueEmpty(q));
return (q->top->value);
}
bool queueEmpty(Queue *q) {
return (q->size == 0);
}
unsigned int queueSize(Queue *q) {
return q->size;
}