#pragma once
#include
#include
using namespace std;
template
struct Node
{
 Node(const T& x)
 :_data(x)
 , _next(NULL)
 {}
 T _data;
 Node* _next;
};
template
class Queue
{
 //先进先出
public:
 Queue()
  :_head(NULL)
  , _tail(NULL)
 {}
 void Push(const T&x)
 {
  if (_head == NULL)
  {
   _head = new Node(x);
   _tail = _head;
  }
  else
  {
   _tail->_next = new Node(x);
   _tail = _tail->_next;
  }
 }
 void Pop()
 {
  if (_head == _tail)
  {
   delete _head;
   _head = _tail = NULL;
  }
  else
  {
   Node*del = _head;
   _head = _head->_next;
   delete del;
  }
 }
 bool IsEmpty()
 {
  return _head == NULL;
 }
 const T& Front()
 {
  assert(_head);//需判断
  return _head->_data;
 }
 const T& Back()
 {
  assert(_tail);
  return _tail->_data;
 }
protected:
 Node* _head;
 Node* _tail;
};
void TestQueue()
{
 Queue q1;
 q1.Push(1);
 q1.Push(2);
 q1.Push(3);
 q1.Push(4);
 q1.Push(5);
 q1.Push(6);
 while (!q1.IsEmpty())
 {
  cout << q1.Front() << " ";
  q1.Pop();
 }
 cout << endl;
}
void  TestQueue1()
{
 Queue q2;
 q2.Push("ab");
 q2.Push("cd");
 q2.Push("ef");
 q2.Push("gh");
 q2.Push("lm");
 q2.Push("kl");
 while (!q2.IsEmpty())
 {
  cout << q2.Front() << " ";
  q2.Pop();
 }
 cout << endl;
}


#include
using namespace std;
#include"Queue.h"
int main()
{
 //栈的特点:后进先出,只能从尾部进行操作
 //TestStack1();
 TestQueue1();
 system("pause");
 return 0;
}