Home > Back-end >  Help to modify the main function
Help to modify the main function

Time:09-26

Keyboard input a string, using the results of the binary tree preorder traversal a binary tree, and three kinds of traversal methods to print, compare is consistent with their own thought, to the depth of the tree, points 1 degree, the node number 2 degrees, the exchange of binary tree left and right subtrees and output after the exchange of sequence traversal results verify the correctness of the exchange, find the order in the binary tree traversal last nodes and the output value,
(1) void visit (BiTree p) output node of pointer to p *//*
(2) the void Preorder sequence traversal before BiTree (T)/* */
(3) the void Inorder BiTree (T)/sequence traversal of * */
(4) void Postorder BiTree (T)/sequence traversal after * */
(5) BiTree CreateTree ()/* sequence established binary tree traversal order before */
(6) int deep (BiTree T) binary tree depth/* o */
(7) int leaf leaf nodes BiTree (T)/* o */
(8) int OneChild BiTree (T) 1 degree knot points/* o */
(9) int TwoChild BiTree (T)/nodes * * o 2 degrees/
(10) void Exchange (BiTree T)/* binary tree left and right subtrees Exchange */
(11) BiTree InorderLastNode BiTree (T);/* sequence in the binary tree traversal last node */
Int main ()
{
BiTree T;
Printf (" \ n sequence traversal of binary tree before: ", CreateTree ());
Printf (" \ n sequence traversal first: ");
Preorder (T);
Printf (" \ n sequence traversal: ");
Inorder (T);
Printf (" \ n sequence traversal: ");
Postorder (T);
printf("\n");
Printf (" the depth of the tree=% d \ n ", deep (T));
Printf (" 1 degree knot points=% d \ n ", OneChild (T));
Printf (" 2 degrees knot points=% d \ n ", TwoChild (T));
Exchange (T);
Inorder (T);
Printf (" sequence in the binary tree traversal last node=% c \ n ", InorderLastNode (T));
return 0;
}
  • Related