数据结构。编写主函数实现顺序栈的基础操作(建栈、入栈、出栈、销毁栈、取栈顶元素、显示栈、清除栈)

2024-11-23 09:54:59
推荐回答(1个)
回答1:

class Stack { private: int top; int s[100]; public: void Ini_Stack(); void Push_Stack(int e); void Pop_Stack(); void Empty(); }void Stack::Ini_Stack() { memset(s, 0, sizeof(s)); top ^= top; }void Stack::Push_Stack(int e) { if(top == sizeof(s)/sizeof(int)) return; s[top++] = e; }void Stack::Pop_Stack() { if(!top) return; --top; }void Stack::Empty() { return (!top); }