www.pudn.com > LL1.rar > stack.h


#if !defined(AFX_STACK_H__AA8994AF_8B3A_477C_A4CC_6F18499CA9BE__INCLUDED_) 
#define AFX_STACK_H__AA8994AF_8B3A_477C_A4CC_6F18499CA9BE__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
const int InitStackSize=50; 
#include 
#include 
using namespace std; 
class Stack   
{ 
public: 
	Stack(); 
	~Stack(); 
 
	void push(char token); 
	char pop(); 
	bool isEmpty(); 
 
private: 
	char *_stack; 
	int _top; 
	int _bottom; 
}; 
 
#endif // !defined(AFX_STACK_H__AA8994AF_8B3A_477C_A4CC_6F18499CA9BE__INCLUDED_) 
 
// stack栈的实现文件 
// Stack.cpp: implementation of the Stack class. 
 
 
 
 
// Construction/Destruction 
 
Stack::Stack() 
{ 
	_stack=new char [InitStackSize]; 
	_top=_bottom=-1; 
} 
 
Stack::~Stack() 
{ 
	_top=_bottom=-1; 
	delete _stack; 
} 
 
 
// Attributes 
 
void Stack::push(char token) 
{ 
	if(_top>=InitStackSize-1) 
	{ 
		cerr<<"Stack is overflow!"<