#include<iostream>
using namespace std;
template<class Type>
class Stack{
private:
int top;
Type *stacka;//用数组存储栈的元素
int maxSize;
public:
Stack(int Size);
//~Stack(){delete[] stack;}
void push(const Type &item);
Type pop(void);
Type getTop();
int empty(void) const{return top==-1;}
int full(void) const{return maxSize-1;}
void clear(void){top==-1;}
};
template<class Type>
void Stack<Type> ::push(const Type &item){
if(full())
{cout<<"stack is full"<<endl;
exit(1);}
top++;
stacka[top]=item;
}
template<class Type>
Type Stack<Type> ::pop(){
if(empty())
{cout<<"stack is empty!"<<endl;
exit(1);}
Type data=stacka[top];//栈不空,取栈顶元素
top--;
return 0;//返回栈顶元素
}
template<class Type>
Type Stack<Type> ::getTop(){
if(empty())
{cout<<"stack is empty!"<<endl;
exit(1);}
return stacka[top];//栈不空,取栈顶元素
}
int main(){
typedef Stack<int> IntStack;
IntStack s;
for(int i=0;i<10;i++)
{
s.push(i);
}
for(int i=0;i<10;i++)
{
cout<<"翻转后:"<<s.pop()<<endl;
}
}
报错是45 cpp no matching function for call to `Stack<int>::Stack()'
cpp:4 candidates are: Stack<int>::Stack(const Stack<int>&)
白板的微信
泛舟湖上清波郎朗
莫回无
随时随地看视频慕课网APP
相关分类