1、二叉树的建立---顺序存储
2、顺序存储结构的遍历
3、二叉树的顺序存储结构转化为链式存储结构
4、二叉树的链式存储结构转化为顺序存储结构
typedef struct BiTreeNode{
BiTreeNode *lchild,*rchild;
void CreatBiTree_0(int arr[],int root,int n){//root用来记录下标
if(root * 2 + 1 <= n - 1)
CreatBiTree_0(arr,root * 2 + 1,n);
if(root * 2 + 2 <= n - 1)
CreatBiTree_0(arr,root * 2 + 2,n);
void CreatBiTree_1(int arr[],int root,int n){//root用来记录下标
CreatBiTree_1(arr,root * 2,n);
if(root * 2 + 1 <= n - 1)
CreatBiTree_1(arr,root * 2 + 1,n);
void PreOrderSq(int node[],int root,int n){
if(root <= n - 1 && node[root] != -1){//当node数组中有节点时
printf("%d ",node[root]);
PreOrderSq(node,2 * root,n);
PreOrderSq(node,2 * root + 1,n);
void InOrderSq(int node[],int root,int n){
if(root <= n - 1 && node[root] != -1){//当node数组中有节点时
InOrderSq(node,2 * root,n);
printf("%d ",node[root]);
InOrderSq(node,2 * root + 1,n);
void PostOrderSq(int node[],int root,int n){
if(root <= n - 1 && node[root] != -1){//当node数组中有节点时
PostOrderSq(node,2 * root,n);
PostOrderSq(node,2 * root + 1,n);
printf("%d ",node[root]);
int num;//num代表T节点在顺序存储的节点数组中的位置
BiTree BuildSqToLinkByLevel(int arr[],int n){
Node Queue[MaxSize],p;//p每次出队的时候要用到
int front = -1,rear = -1;//用来标记Queue
BiTree T = (BiTree)malloc(sizeof(BiTreeNode));
Queue[++rear] = {T,1};//相当于Queue[rear].T = T;Queue[rear].num = 1;
p = Queue[++front];//出队一个元素
if(arr[p.num * 2] == -1 || p.num * 2 > n)
p.T -> lchild = (BiTree)malloc(sizeof(BiTreeNode));
p.T -> lchild -> data = arr[p.num * 2];
Queue[++rear] = {p.T -> lchild,p.num * 2};
if(arr[p.num * 2 + 1] == -1 || p.num * 2 + 1 > n)
p.T -> rchild = (BiTree)malloc(sizeof(BiTreeNode));
p.T -> rchild -> data = arr[p.num * 2 + 1];
Queue[++rear] = {p.T -> rchild,p.num * 2 + 1};
BiTree BuildLinkToSq(BiTree T,int arr[],int root){
BuildLinkToSq(T -> lchild,arr,root * 2);
BuildLinkToSq(T -> rchild,arr,root * 2 + 1);
