问题 填空题

请将下列栈类Stack补充完整。 class Stack{ private: int pList[100]; //int数组,用于存储占的元素 int top; //栈顶元素(数组下标) public: Stack( ):top(0){ } void Push(const int&item); //新元素item压入栈 int Pop(void); //将栈顶元素弹出栈 }; void Stack::Push(const int&item){ if(top==99) exit(1); //如果栈满,则程序终止 top++; //栈顶指针增1 ______; } int Stack::Pop( ){ if(top<0) exit(1); //如果栈空,则程序终止 return Plist[top--]; }

答案

参考答案:plist[top]=item

解析: 栈的操作,进栈时,先将栈顶指针向上移动,然后将元素压入到栈中,故这里应填入plist[top]=item。

加标点题
名词解释