forked from dale48/levawc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
66 lines (52 loc) · 1.11 KB
/
queue.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* _____
* ANSI / ___/
* / /__
* \___/
*
* Filename: queue.c
* Author : Kyle Loudon/Dan Levin
* Date : Fri Mar 22 12:40:45 GMT 2013
* Version : 0.40
* ---
* Description: An implementation of a generic, queue ADT.
*
* 2013-02-19 Made some revision to the Doxygen documentation. Enhanced the description of
* in/out parameters - i.e. double-pointers.
*/
/**
* @file queue.c
*
**/
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
/* FUNCTION DEFINITIONS --------------------------------------------------- */
Queue QUEUEinit(void (*destroy)(void *data))
{
return SLISTinit(destroy);
}
void QUEUEdestroy(Queue que)
{
SLISTdestroy(que);
}
int QUEUEenqueue(Queue que, const void *data)
{
return SLISTinsnext(que, SLISTtail(que), data);
}
int QUEUEdequeue(Queue que, void **data)
{
return SLISTremnext(que, NULL, data);
}
void *QUEUEpeek(Queue que)
{
return SLISTsize(que) == 0 ? NULL : SLISTdata(SLISThead(que));
}
int QUEUEisempty(Queue que)
{
return SLISTsize(que) == 0 ? 1 : 0;
}
int QUEUEsize(Queue que)
{
return SLISTsize(que);
}