#include
#include
typedef char datatype;//二叉樹結點的資訊型別
typedef enum tagtype;//結點域是鏈結還是線索的判斷
typedef struct bitnode//二叉樹結點型別
bitnode;
int inthreading(bitnode *thr);
bitnode *pre,*thr;//thr是線索二叉樹的頭指標
bitnode *createbitree()//先序遞迴法建樹
if ((t->rchild = createbitree()) != null)
}
return t;
}
int inorderthr(bitnode *t)//中序遍歷二叉樹,並將其線索化,thr為其lchild指向根節點的樹的頭結點,用於構建一棵雙向線索樹
else
return 1;
}
int inthreading(bitnode *t)//遞迴法線索化二叉樹
if (!pre->rchild)//右子樹為空,則pre指標指向結點的後繼為當前結點
pre = t;
inthreading(t->rchild);//線索化右子樹
}
return 1;
}
int inordertra(bitnode *thr)//中序非遞迴遍歷線索二叉樹,thr為二叉樹的頭結點非根結點
printf("%c",p->data);//訪問無左子樹的結點
while (p->rtag == thread && p->rchild != thr)//順線索訪問其後序結點
p = p->rchild;
}
return 1;
}
void main()
根據二叉樹的先序遍歷和中序遍歷建立二叉樹
根據二叉樹的先序遍歷和中序遍歷建立二叉樹 rebacktree 根據二叉樹的先序遍歷和中序遍歷建立二叉樹。rebacktree1 根據二叉樹的後序序遍歷和中序遍歷建立二叉樹。include stdio.h include stdlib.h typedef struct node node,nodep...
建立二叉樹並中序遍歷
題目描述 編乙個程式,讀入使用者輸入的一串先序遍歷字串,根據此字串建立乙個二叉樹 以指標方式儲存 例如如下的先序遍歷字串 abc de g f 其中 表示的是空格,空格字元代表空樹。建立起此二叉樹以後,再對二叉樹進行中序遍歷,輸出遍歷結果。輸入輸入有多組測試資料。每組資料為一行字串,長度不超過100...
二叉樹中序遍歷
訪問根結點的的左子樹,訪問根結點和訪問根結點的右子樹依次記作 l,d r 中序遍歷 ldr 演算法 遍歷根結點的左子樹,訪問根結點 遍歷根結點的右子樹 對於上面的圖,我們假定只有a,b,c三個結點,則中序遍歷結果為 b a c 採用上節 二叉樹鏈式儲存和前序遍歷 中的遞迴推演 db a c d b ...