-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue.h
More file actions
57 lines (55 loc) · 1.42 KB
/
Copy pathQueue.h
File metadata and controls
57 lines (55 loc) · 1.42 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
//
// Created by ge yao on 2017/7/29.
// Queue
//
#ifndef LINEARLIST_QUEUE_H
#define LINEARLIST_QUEUE_H
#include "DoubleLinkedLinearList.h"
using namespace std;
template <class T>
class Queue{
private:
DoubleLinkedLinearList<T>* dList = new DoubleLinkedLinearList<T>();
public:
virtual T pop(){
if (isEmpty()){
return (T) NULL; //TODO
} else{
DNode<T> head = * dList->getHead();
dList->remove(dList->getHead());
return head.getDataNode();
}
}
virtual bool push(T* dataNode){
if (dList == nullptr){
dList = new DoubleLinkedLinearList<T>();
}
DNode<T>* dNode = new DNode<T>();
dNode->setDataNode(* dataNode);
return dList->add(dNode);
}
virtual bool isEmpty(){
if (dList == nullptr){
dList = new DoubleLinkedLinearList<T>();
return true;
} else{
return dList->empty();
}
}
virtual int size(){
if (dList == nullptr){
dList = new DoubleLinkedLinearList<T>();
return 0;
} else{
return dList->getSize();
}
}
virtual void info(){
cout << "Queue info" << endl;
cout << "Size " << size() << endl;
cout << "isEmpty " << isEmpty() << endl;
cout << "List inside Info ----- " << endl;
this->dList->info();
}
};
#endif //LINEARLIST_QUEUE_H