-
Notifications
You must be signed in to change notification settings - Fork 5
/
MinPriorityQueue.h
106 lines (90 loc) · 1.96 KB
/
MinPriorityQueue.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
// Author : XuBenHao
// Version : 1.0.0
// Mail : xbh370970843@163.com
// Copyright : XuBenHao 2020 - 2030
#ifndef AILIB_DATASTRUCT_QUEUE_PRIORITYQUEUE_H
#define AILIB_DATASTRUCT_QUEUE_PRIORITYQUEUE_H
#include "..\..\stdafx.h"
#include "..\Heap\MinHeap.h"
namespace AlLib
{
namespace DataStruct
{
namespace Queue
{
template <typename T>
class MinPriorityQueue
{
public:
MinPriorityQueue();
virtual ~MinPriorityQueue();
MinPriorityQueue(const MinPriorityQueue& dqA_);
MinPriorityQueue& operator=(const MinPriorityQueue& dqA_);
void In(const T& nValue_);
T Out();
T Peek() const;
bool IsEmpty() const;
Heap::MinHeap<T> GetHeap() const
{
return m_mhHeap;
}
private:
Heap::MinHeap<T> m_mhHeap;
};
template <typename T>
MinPriorityQueue<T>::MinPriorityQueue()
{
}
template <typename T>
MinPriorityQueue<T>::~MinPriorityQueue()
{
}
template <typename T>
MinPriorityQueue<T>::MinPriorityQueue(const MinPriorityQueue& mpqA_)
{
m_mhHeap = mpqA_.m_mhHeap;
}
template <typename T>
typename MinPriorityQueue<T>& MinPriorityQueue<T>::operator=(const MinPriorityQueue& mpqA_)
{
if (this == &mpqA_)
{
return *this;
}
m_mhHeap = mpqA_.m_mhHeap;
return *this;
}
template <typename T>
void MinPriorityQueue<T>::In(const T& nValue_)
{
m_mhHeap.Add(nValue_);
}
template <typename T>
typename T MinPriorityQueue<T>::Out()
{
if (IsEmpty())
{
throw "queue is empty";
}
T _nValue = m_mhHeap.Get(1);
m_mhHeap.Delete(1);
return _nValue;
}
template <typename T>
typename T MinPriorityQueue<T>::Peek() const
{
if (IsEmpty())
{
throw "queue is empty";
}
return m_mhHeap.Get(1);
}
template <typename T>
bool MinPriorityQueue<T>::IsEmpty() const
{
return m_mhHeap.GetSize() <= 1;
}
}
}
}
#endif