Chained storage instance _c language for C-language binary tree

Source: Internet
Author: User

Chained storage of binary tree

To achieve the basic operation of the two-fork tree: Establishment, traversal, calculation depth, knot number, leaves and so on.

Enter C, first preface to create two fork tree, #表示空节点;

Input h: Compute the height of the binary tree;

Input L: Calculate the number of the leaves of the binary tree;

Input N: Compute the total number of binary tree nodes;

Input 1: First sequence traversing the binary tree;

Input 2: Middle sequence traversal binary tree;

Input 3: Subsequent traversal of the binary tree;

Enter F: Find the number of nodes in the value =x;

Enter P: Prints all nodes in indented text.

It's simply not necessary to explain the code.

#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Two-fork tree chain storage means * * typedef char DATATYPE;
 /* The actual type of user-defined DataType/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 text form to represent the binary tree/void Createbintree (Bintree *t); /* Construct two fork list */void preorder (Bintree T); /* Pre-order traversal binary tree/void Inorder (Bintree T); /* In-order traversal binary tree/void Postorder (Bintree T);  /* Subsequent traversal of the binary tree/INT nodes (Bintree T);  /* COMPUTE Summary points */int leafs (Bintree T);  /* Calculate the total number of leaves */int hight (Bintree T); /* Compute the height of the binary tree/int Find (Bintree T,char x);
 The number of nodes looking for value =x; int main () {Bintree T;
 Char FLG;
  while (CIN&GT;&GT;FLG) switch (FLG) {case ' C ': GetChar ();
  Createbintree (&t); cout<< "Created success!"
  <<endl;
 Break Case ' H ': cout<< "height=" < 

Above is a binary tree chain storage of a small example, need to learn to students please refer to, thank you support

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.