头文件:
#pragma once templateclass Seqstack { T date[MaxSize]; int top; public: Seqstack(); void Push(T x); T pop(); T Top(); bool Empty(); void Clear(); };
cpp:文件
#include "pch.h" #include "Seqstack.h" templateSeqstack ::Seqstack() { top = -1; } template bool Seqstack ::Empty() { return (top = -1); } template void Seqstack ::Push(T x) { if (top == MaxSize - 1) { AfxMessageBox(L"错误!超过了栈的大小!"); exit(-1); } top++; date[top] = x; } template T Seqstack ::pop() { if (top == -1) { //AfxMessageBox(L"错误!栈向下溢出!"); return NULL; //exit(-1); } T x = date[top]; top--; return x; } template T Seqstack ::Top() { if (top == -1) { //AfxMessageBox(L"错误!栈向下溢出!"); return NULL; //exit(-1); } return date[top]; } template void Seqstack ::Clear() { top = -1; }



