The data structure of this semester is not very good. Spoof ing...
Tell the first and middle sequence of the Binary Tree, and find the latter sequence.
Idea: first establish a binary linked list and then traverse the binary tree.
# Include <cstdio> <br/> using namespace STD; <br/> typedef struct binary <br/>{< br/> int data; <br/> binary * lchild, * rchild; <br/> binary () <br/>{< br/> lchild = NULL; <br/> rchild = NULL; <br/>}< br/>} * bittree; <br/> int pre [1010], in [1010]; <br/> void build (bittree & root, int Len, int PST, int Ped, int inst, int INED) // first order creation <br/> {<br/> int I, l_len = 0; <br/> If (LEN <= 0) <br/> return; <br/> r OOT = new binary; <br/> root-> DATA = pre [PST]; <br/> for (I = inst; I <= ined; I ++) <br/> {<br/> If (in [I] = pre [PST]) <br/> {<br/> l_len = I-Inst; <br/> break; <br/>}< br/> build (root-> lchild, l_len, Pst + 1, Pst + l_len, inst, i-1); <br/> build (root-> rchild, len-1-l_len, Pst + l_len + 1, Ped, I + 1, INED ); <br/>}< br/> void travel (Binary * root) // post-order traversal <br/> {<br/> int I; <br/> If (Root) <br/> {<Br/> travel (root-> lchild); <br/> travel (root-> rchild); <br/> printf ("% d ", root-> data); <br/>}< br/> int main () <br/>{< br/> int I, N; <br/> bittree root; </P> <p> while (scanf ("% d", & N )! = EOF) <br/>{< br/> for (I = 0; I <n; I ++) <br/>{< br/> scanf ("% d", & Pre [I]); <br/>}< br/> for (I = 0; I <n; I ++) <br/>{< br/> scanf ("% d", & in [I]); <br/>}< br/> build (root, N, 0, n-1, 0, n-1); <br/> travel (root-> lchild ); <br/> travel (root-> rchild); <br/> printf ("% d/N", root-> data ); <br/>}< br/> return 0; <br/>}