📄 stack.h
字号:
#include<iostream>
#include<stdlib.h>
const int MaxStackSize=150;
template<class T>
class Stack
{
private:
T Stacklist[MaxStackSize];
int top;
public:
Stack(void);
void push(T item);
T pop(void);
void ClearStack(void);
T Peek(void);
int StackEmpty(void);
int StackFull(void);
int recount();
};
template<class T>
Stack<T> ::Stack(void):top(-1){}
template<class T>
void Stack<T> ::push(T item)
{
if(top==MaxStackSize-1)
{
cout<<"Stack overflow!"<<endl;
exit(1);
}
top++;
Stacklist[top]=item;
//return Stacklist[top];
}
template<class T>
T Stack<T> ::pop(void)
{
T temp;
if(top==-1)
{
cout<<"Attempt to pop an empty Stack!"<<endl;
exit(1);
}
temp=Stacklist[top];
top--;
return temp;
}
template<class T>
void Stack<T> ::ClearStack(void)
{
top=-1;
}
template<class T>
T Stack<T> ::Peek(void)
{
if(top==-1)
{
cout<<"Attempt topeek an empty Stack"<<endl;
exit(1);
}
return Stacklist[top];
}
template<class T>
int Stack<T> ::StackEmpty(void)
{
return top==-1;
}
template<class T>
int Stack<T> ::StackFull(void)
{
return top==MaxStackSize-1;
}
template<class T>
int Stack<T> ::recount(void)
{
int temp;temp=top+1;
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -