forked from asayler/CU-CS3753-PA2
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathqueue.h
67 lines (54 loc) · 1.44 KB
/
queue.h
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
/*
* File: queue.h
* Author: Chris Wailes <chris.wailes@gmail.com>
* Author: Wei-Te Chen <weite.chen@colorado.edu>
* Author: Andy Sayler <andy.sayler@gmail.com>
* Project: CSCI 3753 Programming Assignment 2
* Create Date: 2010/02/12
* Modify Date: 2011/02/05
* Modify Date: 2012/02/01
* Description:
* This is the header file for an implemenation of a simple FIFO queue.
*
*/
#ifndef QUEUE_H
#define QUEUE_H
#include <stdio.h>
#define QUEUEMAXSIZE 50
#define QUEUE_FAILURE -1
#define QUEUE_SUCCESS 0
typedef struct queue_node_s{
void* payload;
} queue_node;
typedef struct queue_s{
queue_node* array;
int front;
int rear;
int maxSize;
} queue;
/* Function to initilze a new queue
* On success, returns queue size
* On failure, returns QUEUE_FAILURE
* Must be called before queue is used
*/
int queue_init(queue* q, int size);
/* Function to test if queue is empty
* Returns 1 if empty, 0 otherwise
*/
int queue_is_empty(queue* q);
/* Function to test if queue is full
* Returns 1 if full, 0 otherwise
*/
int queue_is_full(queue* q);
/* Function add payload to end of FIFO queue
* Returns QUEUE_SUCCESS if the push successeds.
* Returns QUEUE_FAILURE if the push fails
*/
int queue_push(queue* q, void* payload);
/* Function to return element from queue in FIFO order
* Returns NULL pointer if queue is empty
*/
void* queue_pop(queue* q);
/* Function to free queue memory */
void queue_cleanup(queue* q);
#endif