求问大神们,下面这个栈的操作哪里出问题了???求知识,急,初学者,数据结构、、、、
SeqStack.h#ifndef SeqStack_H
#define SeqStack_H
const int StackSize=10;
template<class T>
class SeqStack
{
public:
SeqStack(){top=-1;}
~SeqStack(){}
void push(T x);
T pop();
T GetTop();
int Empty();
private:
T data[StackSize];
int top;
}
#endif
SeqStack.cpp
#include"SeqStack.h"
template <class T>
void SeqStack<T>::push(T x)
{
int top;
if(top==StackSize-1)throw"上溢";
data[++top]=x;
}
template <class T>
T SeqStack<T>::pop()
{
T x;
if(top==-1)throw"下溢";
else
x=data[top--];
return x;
}
template <class T>
T SeqStack<T>::GetTop()
{
if(top==-1)throw"下溢";
else
return data[top];
}
template <class T>
int SeqStack<T>::Empty()
{
if(top==-1)return 1;
else return 0;
}
MainSeqStack.cpp
#include"SeqStack.cpp"
#include<iostream>
using namespace std;
void main()
{
SeqStack<int>a;
cout<<"执行压栈操作:"<<endl;
try
{
a.push(1);
a.push(2);
a.push(3);
a.push(4);
}
catch(char* wrong)
{
cout << wrong; //如失败提示失败信息
}
cout<<"已经插入“1,2,3,4”"<<endl;
cout<<"执行判断栈是否为空操作:"<<endl;
cout<<a.Empty()<<endl;
cout<<"执行出栈操作:"<<endl;
cout<<a.pop()<<endl;
cout<<"弹出栈顶元素:"<<endl;
cout<<a.GetTop()<<endl;
}