#include<iostream> using namespace std; struct Node{ int data; Node *next; Node(const int& Newdata, Node* nextnode=NULL):data(Newdata), next(nextnode){ } }; class Queue{ private: Node *front; Node *rear; int count; public: Queue(); ~Queue(); bool empty(); void push(int x); void pop(); void clear(); int Length(); int Front(); }; Queue::Queue():front (NULL), rear (NULL), count(0){ } Queue::~Queue() { clear(); } void Queue::push(int x) { if (front == NULL) front = rear = new Node(x); else { Node *q = new Node(x); rear->next = q; rear = q; } count++; } int Queue::Length() { return count; } bool Queue::empty(){ return front == NULL; } void Queue::pop() { if (empty()) { cout<<"错误"<<endl; } Node *q = front; front = front->next; delete q; count--; } void Queue::clear() { while (front) { Node *q = front; front= front->next; delete q; } count=0; } int Queue::Front() { if (empty()) { cout<<"错误"<<endl; } return front->data; } int main() { Queue s; s.push(1); s.push(11); s.push(12); s.push(13); s.push(14); s.push(15); s.push(16); s.push(17); cout<<s.Front()<<endl; cout<<s.Length()<<endl; s.pop(); cout<<s.Length()<<endl; return 0; }