Binary Tree chain storage and binary tree chain Storage

Source: Internet
Author: User

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 = "

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.