数据结构实验的内容,按照实验指导书上的经过修改完善后的。
二叉树重构的是百度搜的,读明白后,添加进来的。
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#define OK 1
#define FELL 0
#define OVERFLOW -2
#define ERROR 0
typedef int Status;
typedef struct LNode
{
char data;
struct LNode *LChild,*RChild;
}LNode,*Tree;
typedef struct
{
Tree *base;
Tree *top;
int size;
}SeqStack; //栈定义
#define INITSIZE 10
#define STACKINCREMENT 1
void InitStack(SeqStack &S)
{//初始化栈
S.base=(Tree *)malloc(INITSIZE*sizeof(Tree));
if(!S.base) exit(OVERFLOW);
S.top=S.base;
S.size=INITSIZE;
}
void Push(SeqStack &S,Tree x)
{ //进栈
if(S.top-S.base>=S.size) //若栈满
{
S.base=(Tree *)realloc(S.base,(S.size+STACKINCREMENT)*sizeof(Tree));
if(!S.base)
exit(OVERFLOW);
S.top=S.base+S.size;
S.size+=STACKINC