template <class T>
struct QueueNode
{
QueueNode<T> *m_pNext;
T m_tValue;
};
template <class T >
class MyQueueList
{
public:
MyQueueList();
~MyQueueList();
void Append(T value);
void* Pup();
int Count();
private:
int m_nLenght;
QueueNode<T>* m_pHead;
QueueNode<T>* m_pLast;
QueueNode<T>* NewNode(T value);
};
template <class T >
MyQueueList<T>::MyQueueList()
{
m_nLenght = 0;
m_pHead = nullptr;
m_pLast = nullptr;
}
template <class T>
MyQueueList<T>::~MyQueueList<T>()
{
}
template <class T>
int MyQueueList<T>::Count()
{
return m_nLenght;
}
template <class T>
QueueNode<T> * MyQueueList<T>::NewNode(T value)
{
QueueNode<T> *pNode = new QueueNode<T> () ;
pNode->m_tValue = value;
pNode->m_pNext = nullptr;
}
template <class T>
void MyQueueList<T>::Append(T value)
{
QueueNode<T> *pNode = NewNode(value);
if(m_pHead ==nullptr)
{
m_pHead = pNode;
}
else
{
m_pLast->m_pNext = pNode;
}
m_pLast = pNode;
m_nLenght++;
}
template <class T>
void* MyQueueList<T>::Pup()
{
if(m_nLenght==0||m_pHead==nullptr)
return nullptr;
QueueNode<T> *pNode = m_pHead;
m_pHead = m_pHead->m_pNext;
pNode->m_pNext = nullptr;
m_nLenght--;
return pNode ;
}
|