Binary tree

xiaoxiao2021-03-06  72

The definition of the binary tree is a recursive definition. The definition and difference between the full binary tree and the fully binary tree. Typedef struct btreenod {elemType Data; Struct btreenode * lc; struct btreenode * rc;} BNode; bnot;

1, the predecessor algorithm of the binary tree VOID Preorder (bt == null) {if (bt == null) return; Else {VIT (BT); if (bt-> lc! = Null) Preorder (BT-> LC); IF (bt-> rc! = null) Preorder (BT-> RC);}} 2 -> lc! = Null) inorder (bt-> lc); Visit (bt); if (bt-> rc! = Null) inorder (bt-> rc);}} 3, the rear sequence algorithm of the binary tree VOID PostOrder (BNODE * BT) {if (bt == null) return; else {if (bt-> lc! = null) PostOrder (bt-> lc); if (bt-> rc! = null) Postorder (bt-> RC); Visit (bt);}}

Three traversal sequences can be obtained from the binary tree. The binary tree can be reconstructed by two traversal sequences.

××× generate binary tree ××× void create_binary_sort_tree (bNode ** proot) {BNODE * P, * q; ELMTYPE KL INT I, N; * proot = NULL; Printf ("INTPUT N:"); scanf (" % D ", & n); for (i = 0; i lc = null; p-> rc = null; printf "INPUT K:"); scanf ("% d", & k); if (* proot = null) * proot = p; else {q = * proot; while (q! = null) {if (q-> data > K) IF (q-> lc! = null) q = q-> lc; else {q-> lc = p; q = null;} if (Q-> Data RC! = NULL) q = q-> rc; else {q-> rc = p; q = null;}}}}}

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

New Post(0)