标签:
#include<iostream> using namespace std; class Stack { int top; int data[10]; public: Stack(); bool empty(); void push(int dat); int pop(); }; Stack::Stack() { top = 0; } bool Stack::empty() { return top == 0; } void Stack::push(int dat) { data[++top] = dat; } int Stack::pop() { if (empty()) { cout << "underfloa" << endl; return -1; } top--; return data[top + 1]; } int main() { Stack s; s.push(1); s.push(2); s.push(3); while (!s.empty()) cout << s.pop() << " "; cout << "\n"; }
标签:
原文地址:http://www.cnblogs.com/liuhg/p/Stack.html