#ifndef _SQSTACK_H_
#define _SQSTACK_H_
#include <iostream>
using namespace std;
enum StatusCode{SUCCESS,RANGE_ERROR,OVER_FLOW,UNDER_FLOW};
const int DEFAULT_SIZE=10;
template<class ElemType>
class SqStack
{
protected:
int count;
int maxSize;
ElemType *elems;
void Init(int size);
bool Full()const;
public:
SqStack(int size=DEFAULT_SIZE);
virtual ~SqStack();//注意虚构函数要是虚函数
bool Empty()const;
void Clear();
int Length()const;
void Traverse(void(* visit)(ElemType &e))const;
StatusCode Push(const ElemType &e);
StatusCode Top(ElemType &e)const;
StatusCode Pop(ElemType &e);
SqStack(const SqStack<ElemType> ©);
SqStack<ElemType>& operator = (const SqStack<ElemType> ©);
};
template<class ElemType>
SqStack<ElemType>::SqStack(int size)
{
elems=NULL;
Init(size);
}
template<class ElemType>
SqStack<ElemType>::~SqStack()
{
del
用顺序栈解决将读入的数按相反的方向解决
最新推荐文章于 2024-05-11 18:07:05 发布