📄 zz.h
字号:
#include<iostream>
using namespace std;
typedef char DataType;
struct BTreeNode//定义二叉树的结点结构
{
public:
DataType data;
BTreeNode *lchild;//左孩子
BTreeNode *rchild;//右孩子
};
class stack
{
public:
stack(int size)
{
vec=new BTreeNode*[size];
top=-1;
MAXSIZE=size;
}
~stack()
{
delete[]vec;
}
int empty()
{
if(top==-1)
return 1;
else
return 0;
}
void push(BTreeNode* x);
BTreeNode* pop();
int top;
int MAXSIZE;
BTreeNode** vec;
};
void stack::push(BTreeNode* x)
{
if(top==MAXSIZE-1)
{
cout<<"overflow"<<endl;
}
else
{
top++;
vec[top]=x;
}
}
BTreeNode* stack::pop()
{
BTreeNode* temp;
if(top==-1)
{
cout<<"underflow"<<endl;
return NULL;
}
else
{
temp=vec[top];
top--;
}
return temp;
}
////////////////////////////////////////////////////////
class stack1
{
public:
stack1(int size)
{
vec=new int[size];
top=-1;
MAXSIZE=size;
}
~stack1()
{
delete[]vec;
}
int empty()
{
if(top==-1)
return 1;
else
return 0;
}
void push(int x);
int pop();
int top;
int MAXSIZE;
int* vec;
};
void stack1::push(int x)
{
if(top==MAXSIZE-1)
{
cout<<"overflow"<<endl;
}
else
{
top++;
vec[top]=x;
}
}
int stack1::pop()
{
int temp;
if(top==-1)
{
cout<<"underflow"<<endl;
return NULL;
}
else
{
temp=vec[top];
top--;
}
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -