CODE_COMPLETION:Binary tree - 14. Comprehensive application (multi level menu)

Luz1个月前 (05-10)题库24
Please write the main function, first create an empty binary tree, and then display the main menu as shown in the figure below for users to choose repeatedly until they choose to exit, and finally destroy the binary tree.
```
I-input o-output c-clear t-traverse d-data q-exit >_
```
-If the user selects wrong, the error will be reported, and the menu will be displayed again to let the user select again.
-If the user selects I or I, enter the binary tree.
-If the user selects o or O, the binary tree will be output.
-If the user selects C or C, the binary tree will be cleared.
-If the user selects t or T, the traversal submenu will be displayed. The user further selects the traversal mode, and then outputs the corresponding traversal results.
-If the user selects D or D, the data submenu will be displayed. The user will further select which data to output.
-If the user chooses Q or Q, exit the program.
Note: the main menu is a repeating menu, which appears repeatedly until the user chooses to exit.
```
1-preorder 2-mesorder 3-postorder 0-return > 1_
```
-If the user selects 1, the result of the traversal will be output.
-If the user chooses 2, the result of post order traversal will be output.
-If the user selects 3, the result of middle order traversal will be output.
```
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 0_
```
-If the user selects 1, the number of nodes will be output.
-If the user selects 2, the number of leaf nodes will be output.
-If the user selects 3, the number of branch nodes will be output.
-If the user selects 4, the depth is output.
Open * main. C * and modify the main function to complete the above functions.
*main.c*
```c
#include
#include
#include "BinTree.h"
/*The code you submit will be embedded here*/
```
The operation effect is as follows:
```
I-input o-output c-clear t-traverse d-data q-exit > x
Incorrect operation option!
I-input o-output c-clear t-traverse d-data q-exit > I
Input: eibj? H? DF? A? G? C##
I-input o-output c-clear t-traverse d-data q-exit > o
Output:
C
G
D
A
F
E
I
H
B
J
I-input o-output c-clear t-traverse d-data q-exit > t
ergodic
1-preorder 2-mesorder 3-postorder 0-return > 9
Incorrect traversal option!
I-input o-output c-clear t-traverse d-data q-exit > t
ergodic
1-preorder 2-mesorder 3-postorder 0-return > 0
I-input o-output c-clear t-traverse d-data q-exit > t
ergodic
1-preorder 2-mesorder 3-postorder 0-return > 1
Preorder traversal: eibjhdfagc
I-input o-output c-clear t-traverse d-data q-exit > t
ergodic
1-preorder 2-mesorder 3-postorder 0-return > 2
I-input o-output c-clear t-traverse d-data q-exit > t
ergodic
1-preorder 2-mesorder 3-postorder 0-return > 3
Postorder traversal: jhbiafcgde
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 9
Incorrect data option!
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 0
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 1
Node number: 10
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 2
Number of leaf nodes: 4
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 3
Number of branch nodes: 6
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 4
Depth: 4
I-input o-output c-clear t-traverse d-data q-exit > C
empty
I-input o-output c-clear t-traverse d-data q-exit > o
Output:
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 1
Node number: 0
I-input o-output c-clear t-traverse d-data q-exit > I
Input: abd × e × CF × G##
I-input o-output c-clear t-traverse d-data q-exit > o
Output:
G
C
F
A
E
B
D
I-input o-output c-clear t-traverse d-data q-exit > d
data
1-node number 2-leaf node number 3-branch node number 4-depth 0-return > 1
Node number: 7
I-input o-output c-clear t-traverse d-data q-exit > Q
```
####Output sample
```out
I-input o-output c-clear t-traverse d-data q-exit >
```
####Input sample
```in
q
```