C++ stack实现 stac.h

#include
using namespace std;

class Stack{


public:
	enum {MaxStack = 5}
	void init() {top=-1;}

	void push(int n)
	{
		if(isFull()){
			errMsg("Full stack. Can't push.");
			return;
		}
		arr[++top] = n;
	}

	int pop(){
		if(isEmpty()){
			errMsg("Empty stack.Popping dummy value.");
			return dummy_val;
		}
		return arr[top--];
	}
	
	bool isEmpty(){return top<0;}
	bool isFull(){return top>MaxStack - 1;}
	void dump(){
		for(int i=top;i>=0;i--)
			cout<<"\t"<

你可能感兴趣的:(C++)