以下是对称序线索化二叉树的算法代码实现,被线索化的二叉树如下:
#include<iostream>
#define MaxSize 10
using namespace std;
//变量定义与声明
typedef char datatype;
typedef struct node
{
datatype data;
struct node *lchild,*rchild;
int ltag,rtag;
}ThrBTnode,*ThrBinTree;
typedef struct
{
ThrBTnode* S[MaxSize];
int top;
}SeqStack;
SeqStack ST;
ThrBinTree root;
ThrBTnode* nodes[10];
//置空栈
void ClearStack(SeqStack &ST)
{
ST.top=-1;
}
//栈的推入
void push(SeqStack &ST,ThrBTnode *p)
{
if(ST.top>=MaxSize-1)
cout<<"overflow!"<<endl;
else
ST.S[++ST.top]=p;
}
//栈的弹出
ThrBTnode* pop(SeqStack &ST,ThrBTnode *p)
{
if(ST.top==-1)
cout<<"underflow!"<<endl;
else
p=ST.S[ST.top--];
return p;
}
//判栈空否
int StackEmpty(SeqStack ST)
{
if(