資源簡(jiǎn)介
二叉樹的先中后遍歷
代碼片段和文件信息
#?include?
#?include?
typedef?char?ElemType;
typedef?struct?BitNode{
ElemType?data;
struct?BitNode?*?lChild;
struct?BitNode?*?rChild;
}BitNode?*BitSortTree;
BitNode?*?creatBitSortTree(); //構(gòu)建二叉排序樹
void?traverseTree(BitSortTree); //遍歷二叉樹
int?main(void)?{
BitSortTree?bst?=?creatBitSortTree();
traverseTree(bst);
return?0;
}
BitNode?*?findPos(BitSortTree?bst?char?findElem)?{
BitNode?*?preNode?=?bst; //記錄前驅(qū)節(jié)點(diǎn)
while(bst?!=?NULL)?{
preNode?=?bst;
if(bst->data?>?findElem)?{
bst?=?bst->lChild;
}?else?{
bst?=?bst->rChild;
}
}
return?preNode;
}
BitNode?*?creatBitSortTree()?{
int?num;
printf(“輸入需要?jiǎng)?chuàng)建多少個(gè)節(jié)點(diǎn):“);
scanf(“%d“?&num);
ElemType?*?arr?=?(ElemType?*)malloc(sizeof(ElemType));
for(int?index=0;?in
- 上一篇:c++premer第五版源代碼.zip
- 下一篇:LR(K)分析方法.doc
評(píng)論
共有 條評(píng)論