自己想了一晚上没睡觉的成果。
我能说我现在越来越觉得编程有趣了么~
堆栈的头文件
#include"stdafx.h"
#define DEFAULTSIZE 100;
#define OK 1;
#define FALSE 0;
template<class ElemType>//回调函数
void visit(ElemType x)
{
cout << x.row<<","<<x.col << endl;
}
template<class ElemType>
class Stack //抽象类
{
public:
virtual int Length() = 0;
virtual bool Push(ElemType e) = 0;
virtual bool Pop(ElemType&x) = 0;
virtual bool Read(ElemType&x) = 0;
virtual void Clear() = 0;
}; //Stack
template<class ElemType>
class SqStack :public Stack<ElemType>//Stack的顺序栈继承
{
private:
ElemType *stack;//栈的存储指针 动态存储分布
int size;
int top;
public:
SqStack(int n = 0);
~SqStack();
void Clear();
int Empty();
int Full();
int Length();
int Size();
bool Push(ElemType e);
bool Pop(ElemType&x);
bool Read(ElemType&x);
int Traverse(void(*visit)(ElemType));
};
template<class ElemType>
SqStack<ElemType>: