-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdequeue.c
More file actions
70 lines (57 loc) · 1.58 KB
/
dequeue.c
File metadata and controls
70 lines (57 loc) · 1.58 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
/*
* ---- The Unbalanced Tree Search (UTS) Benchmark ----
*
* Copyright (c) 2010 See AUTHORS file for copyright holders
*
* This file is part of the unbalanced tree search benchmark. This
* project is licensed under the MIT Open Source license. See the LICENSE
* file for copyright and licensing information.
*
* UTS is a collaborative project between researchers at the University of
* Maryland, the University of North Carolina at Chapel Hill, and the Ohio
* State University. See AUTHORS file for more information.
*
*/
#include "dequeue.h"
#include "dlist.h"
#include <stdlib.h>
dequeue deq_create(){
dequeue q = malloc(sizeof(struct dequeue));
q -> head = dcons(NULL, NULL, NULL);
q -> tail = dcons(NULL, NULL, NULL);
q -> head -> next = q -> tail;
q -> tail -> prev = q -> head;
return q;
}
int deq_isEmpty(dequeue q) {
return q -> head -> next == q -> tail;
}
void deq_pushFront(dequeue q, void *element) {
create_and_link(element, q->head, q->head->next);
}
void deq_pushBack(dequeue q, void *element){
create_and_link(element, q->tail->prev, q->tail);
}
void* deq_popFront(dequeue q){
return unlink_and_free(q->head->next);
}
void* deq_popBack(dequeue q) {
return unlink_and_free(q->tail->prev);
}
void* deq_peekFront(dequeue q){
return q->head->next->element;
}
void* deq_peekBack(dequeue q){
return q->tail->prev->element;
}
void deq_mkEmpty(dequeue q){
while(!deq_isEmpty(q))
deq_popFront(q);
}
int deq_length(dequeue q) {
int count;
dlist e = q->head->next;
for (count = 0; e != q->tail; count++)
e = e->next;
return count;
}