#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#define ERROR 0
#define OK 1
#define SElemType int
#define STACK_INIT_SIZE 64
using namespace std;
class Stack
{
protected:
char name;
int top;
int* base;
int stacksize;
public:
Stack(int size):top(size+1), stacksize(size+1)
{
base = new int[stacksize];
if(!base)
{
cout<<"内存分配失败"<<endl;
exit(OVERFLOW);
}
base[0] = 0;
for(int i=1;i<stacksize;i++)
base[i] = stacksize-i;
}
Stack(int size, int temp):top(1), stacksize(size+1)
{
base = new int[stacksize];
if(!base)
{
cout<<"内存分配失败"<<endl;
exit(OVERFLOW);
}
base[0] = 0;
}
~Stack()//销毁链表
{
delete[] base;
}
void deName(char ch)
{
name = ch;
}
bool Empty_Stack();//销毁链表
void Clear_Stack();//清空链表
void Push_Stack(int e);//插入元素e
void Pop_Stack();//删除栈顶元素
void Visit_Stack();//访问栈,从栈顶到栈底
int Get_Top()//获取栈顶
{
if(top!=0)
return base[top-1];
else
cout<<"栈空..."<<endl;
return 0;
}
int Size_Stack();//获取元素个数,即栈的长度
void PopLine_Stack();//弹出行
char getName()
{
return name;
}
int gettop()
{
return top;
}
};
bool Stack::Empty_Stack()
{
if(top==0)
{
return true;
}
else
return false;
}
void Stack::Clear_Stack()
{
top = 0;
}
void Stack::Push_Stack(int a)
{
if(top+1<=stacksize)
{
base[top] = a;
top++;
}
else
{
cout<<(top);
cout<<"栈满..."<<endl;
exit(1);
}
}
void Stack::Pop_Stack()
{
if(top>0)
{
top--;
}
else
{
cout<<"栈空..."<<endl;
exit(1);
}
}
int Stack::Size_Stack()
{
return top;
}
void Stack::Visit_Stack()
{
int t=0;
while(t<top)
{
cout<<base[t]<<" ";
t++;
}
}