-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.h
72 lines (61 loc) · 1.41 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
68
69
70
71
72
//
// Name: Joowon Byun
// Date: July 22th 2015 ~ July 27th 2015
//
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
#include "QueueNode.h"
using namespace std;
template< typename NODETYPE >
class Queue {
private:
QueueNode< NODETYPE > *front;
QueueNode< NODETYPE > *rear;
public:
Queue();
void pushRear( NODETYPE &in );
void popFront();
void listFromFront();
bool isEmpty();
};
template< typename NODETYPE >
Queue< NODETYPE>::Queue(): front( NULL ), rear( NULL ) {}
template< typename NODETYPE >
void Queue< NODETYPE >::pushRear( NODETYPE &in ) {
QueueNode< NODETYPE > *temp = new QueueNode< NODETYPE >( in, rear );
if ( isEmpty() )
front = rear = temp;
else {
rear->setNext(temp);
rear = temp;
}
}
template< typename NODETYPE >
void Queue< NODETYPE>::popFront() {
QueueNode< NODETYPE > *delTemp = front;
if (isEmpty())
return;
else if (front == rear)
front = rear = NULL;
else {
front = front->next;
front->changePreToNull();
}
delete delTemp;
}
template< typename NODETYPE >
void Queue< NODETYPE>::listFromFront() {
QueueNode< NODETYPE > *temp;
cout << "The data is " << endl;
for ( temp = front ; temp != NULL ; temp = temp->next )
cout << "\t" << temp->data << endl;
cout << endl;
}
template< typename NODETYPE >
bool Queue< NODETYPE>::isEmpty() {
if ( front == NULL )
return true;
return false;
}
#endif