首页 > 代码库 > 链接栈
链接栈
#include <iostream> using namespace std; typedef int stackEntry; const int overflow = 1; const int underflow = 2; const int success = 0; struct Node { stackEntry data; Node *next; }; class stack { public: stack(); bool empty() const; int push(const stackEntry &item); int pop(); int top(stackEntry &item) const; // void operator = (const stack &original); // stack(const stack &original); protected: Node *top_node; }; stack::stack() { top_node = NULL; } int stack::push(const stackEntry &item) { Node *new_top = new Node; //为元素item构建新的节点,该节点指向原来的栈顶元素 if (new_top == NULL) return overflow; new_top->data = http://www.mamicode.com/item;"输入乘客人数n" << endl; cin >> n; cout << "按登机顺序输入乘客编号" << endl; for (int i = 0; i < n; i++) { cin >> item; temp.push(item); } passengers = temp; cout << endl << endl; cout << "乘客下机顺序是:"; while (!passengers.empty()) { passengers.top(item); cout << item << " "; passengers.pop(); } cout << endl; }
链接栈
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。