-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDynQueue.h
108 lines (92 loc) · 1.89 KB
/
DynQueue.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Author : XuBenHao
// Version : 1.0.0
// Mail : [email protected]
// Copyright : XuBenHao 2020 - 2030
#ifndef AILIB_DATASTRUCT_QUEUE_DYNQUEUE_H
#define AILIB_DATASTRUCT_QUEUE_DYNQUEUE_H
#include "..\..\stdafx.h"
#include "..\List\DoubleList.h"
namespace AlLib
{
namespace DataStruct
{
namespace Queue
{
template <typename T>
class DynQueue
{
public:
DynQueue();
virtual ~DynQueue();
DynQueue(const DynQueue& dqA_);
DynQueue& operator=(const DynQueue& dqA_);
void In(const T& nValue_);
T Out();
T Peek() const;
bool IsEmpty() const;
List::DoubleList<T> GetList() const
{
return m_List;
}
private:
List::DoubleList<T> m_List;
};
template <typename T>
DynQueue<T>::DynQueue()
{
}
template <typename T>
DynQueue<T>::~DynQueue()
{
}
template <typename T>
DynQueue<T>::DynQueue(const DynQueue& dqA_)
{
m_List = dqA_.m_List;
}
template <typename T>
typename DynQueue<T>& DynQueue<T>::operator=(const DynQueue& dqA_)
{
if (this == &dqA_)
{
return *this;
}
m_List = dqA_.m_List;
return *this;
}
template <typename T>
void DynQueue<T>::In(const T& nValue_)
{
m_List.InsertLast(nValue_);
}
template <typename T>
T DynQueue<T>::Out()
{
if (IsEmpty())
{
throw "queue is empty";
}
List::DoubleList<T>::Node* _pFirst = m_List.GetFirst();
T _nValue = _pFirst->GetValue();
m_List.DeleteFirst();
return _nValue;
}
template <typename T>
T DynQueue<T>::Peek() const
{
if (IsEmpty())
{
throw "queue is empty";
}
List::DoubleList<T>::Node* _pFirst = m_List.GetFirst();
return _pFirst->GetValue();
}
template <typename T>
bool DynQueue<T>::IsEmpty() const
{
return m_List.IsEmpty();
}
}
}
}
#endif