zz.h

来自「包括建立输出前序遍历中序遍历后序遍历、求树高统计叶子总数等」· C头文件 代码 · 共 126 行

H
126
字号
#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 + =
减小字号Ctrl + -
显示快捷键?