#include<iostream.h> class sque { private: int front,rear,count,maxsize; int *elem; public: sque(int size) { maxsize=size; count=front=rear=0; elem=new int[maxsize]; } int length() { return count; } void inque(int &e) { if(count==maxsize) cout<<"栈已满"<<endl; else { elem[rear]=e; rear=(rear+1)%maxsize; count++; } } void ouque(int &e) { if(count==0) cout<<"栈中已无元素"<<endl; else { e=elem[front]; front=(front+1)%maxsize; count--; } } void accessnode() { } }; void main() { int size; int n,temp; cout<<"请输入栈的最大空间"<<endl; cin>>size; sque sque1(size); while(1) { cout<<"请输入一个整数,0表示结束输入"<<endl; cin>>n; if(n==0) break; else if(n>0) { sque1.inque(n); } else sque1.ouque(temp); } cout<<"栈的长度为"<<sque1.length()<<endl; }