Data structure of the binary tree

xiaoxiao2021-03-31  228

Typedef struct btree {

ELMTYPE DATA; // Assume first as int

Struct btree * lchild, * rchild;

Btree;

Recrusive recursive

Order

Void Preorder (btree * bt) {

Printf ("% D / T", BT-> DATA);

Preoder (BT-> LCHILD);

Preorder (bt-> rchild)

Return ;;

}

Order

Void MIDORDER (BTREE * BT) {

MIDORDER (BT-> LCHILD);

Printf ("% D / T", BT-> DATA);

MIDORDER (BT-> rchild);

Return;

}

Resequence

Void PostOrder (btree * bt) {

PostORDER (BT-> LCHILD);

Postorder (bt-> rchild);

Printf ("% D / T", BT-> DATA);

Return;

}

Change the left and right sub-tree position of the binary tree

Void Exchange (btree * b) {

BTree * temp;

IF (bt! = null) {

Temp = bt-> LCHILD;

Bt-> lchild = bt-> rChild;

BT-> rChild = Temp;

Exchange (BT-> LCHILD);

Exchange (bt-> rchild);

}

}

转载请注明原文地址:https://www.9cbs.com/read-130971.html

New Post(0)