A pre-sequence and sequence sequence of a binary tree is known, the only one-two-fork tree is known.

xiaoxiao2021-03-31  196

A sequence of sequence and sequence sequences of a binary tree are known, and the only two-fork tree is defined, thereby constructing the recurrent algorithm of the binary tree.

Setting the pre-sequence sequence and the sequence sequence store two one-dimensional array, PRE (1, N), and IND (1, N), in pre-sequence sequence pre (I, j), and sequence sequence Ind (u, v) Recursively constructing a binary tree, its root node pointer is s.

TypedEf struct bnota; struct bNode * left, * right;} btree; btree * bintree (int I, int J, int u, intv) {INT K, L; BTREE * head, * s; head = null ; If (j> = i) {head = new btree; // establish root knot head-> data = pre [i]; k = u; while (ind [k]! = Pre [i]) k ///// Find root node L = I ku; // L is the position IF (k == u) // left sub-tree in the left sub-tree in the left sub-tree. -> left = null; else {s = bintree (i 1, l, u, k-1); // Construct the left subtree head-> left = S;} if (k == v) // Right Tree is empty Head-> Right = null; else {s = bintree (l 1, j, k 1, v); // Construct the right child head-> Right = S;}} RTURN head;}

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

New Post(0)