-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.c
72 lines (52 loc) · 1.48 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
66
67
68
69
70
71
72
/*
Author: Ben Richmond and Christian Black
Assaignment Number: 1
Date of Submission: TBD
Short Description of Contents:
These are the functinos to queue and dequeue various Node objects from the Queue
*/
#include "Queue.h"
/*
Function Name: enqueue
Input to the Method: The node to be added as well as the mainQueue that we are adding
it to
Output: There is no output
Brief Description of the Task:
Sets the pointer of the array's last filled element's next position to a
Node object.
*/
void enqueue(Node* addend, Queue* mainQueue)
{
int pointAddend = mainQueue->last;
Node tempNode;
tempNode.num = addend->num;
tempNode.level = addend->level;
mainQueue->arr[pointAddend] = tempNode;
//Updates the mainQueue's variables
(mainQueue->length)++;
(mainQueue->last)++;
}
/*
Function Name: dequeue
Input to the Method: the queue that we are pulling from
Output: Returns a pointer to the node that was the first into the queue.
Brief Description:
First checks to make sure that the queue isn't empty then remove the item at
the first position and increments and returns appropriately
*/
Node dequeue(Queue* mainQueue)
{
//Error checking if Statement and error code
if (mainQueue->length <= 0){
printf("Error invalid Queue");
Node node;
return node;
}
//If it passes creates a reference to the first item in the queue then increment
else{
Node fin = mainQueue->arr[mainQueue->first];
(mainQueue->first)++;
(mainQueue->length)--;
return fin;
}
}