Binary Tree chain storage and binary tree chain Storage
Basic operations for Binary Trees: Build, traverse, calculate depth, number of knots, and number of leaves.
Enter C and create a binary tree in sequence. # It indicates an empty node;
Input H: calculates the height of a binary tree;
Input L: calculates the number of leaves of a binary tree;
Input N: calculates the total number of Binary Tree nodes;
Input 1: traverse Binary Trees in sequence;
Input 2: traverse the binary tree in the middle order;
Input 3: traverse the binary tree;
Enter F: the number of nodes with the search value = x;
Input P: All nodes are output in the form of scaled text.
It's very simple and you don't need to explain it much.
# Include <stdio. h> # include <stdlib. h> # include <iostream> using namespace std;/* chained storage of Binary Trees */typedef char ype; /* the actual type of DataType should be defined by the user */typedef struct node {DataType data; node * lchild, * rchild;/* Left and Right child pointer */} BinTNode; /* node type */typedef BinTNode * BinTree; int sum = 0; void DisplayBinTree (BinTree T ); /* use the format of lattice text to represent the binary tree */void CreateBinTree (BinTree * T);/* construct the binary linked list */void Preorder (BinTree T ); /* traverse binary tree in the forward Order */void Inorder (B InTree T);/* middle-order traversal of Binary Trees */void Postorder (BinTree T);/* post-order traversal of Binary Trees */int nodes (BinTree T ); /* calculate the sum points */int leafs (BinTree T);/* calculate the total number of leaves */int hight (BinTree T ); /* calculate the height of a binary tree */int find (BinTree T, char x); // The number of nodes with the search value = x; int main () {BinTree T; char flg; while (cin> flg) switch (flg) {case 'C': getchar (); CreateBinTree (& T); cout <"Created success! "<Endl; break; case 'H': cout <" Height = "