Data structure on-machine examination (Kai shen Version)//modified binary tree

Source: Internet
Author: User

node* buildtree (int m) {//This is the wrong two-fork-tree method//null case cannot be judged    if (M > N) return null;    printf ("Please enter the value of the%d/%d node:", m,n);    Node *node = (node*) malloc (sizeof (node));    int V;    scanf ("%d", &v);    node, value = V;    Node-to  -left = Buildtree (M * 2);    Node-right = Buildtree (M * 2 + 1);    return node;}

I think this binary tree has problems, can only deal with a relatively complete two-fork tree, once the binary tree has some empty nodes, it will not solve the problem.

My code is attached below:

/** Two fork Tree establishment method one *2014.12.17*/root Create_ () {     root n;     Char v;     V=getchar ();     if (v== ')          return NULL;     else {          if (! ( N= (node*) malloc (sizeof (node)))          {              printf ("Failed to allocate memory");              Exit (1);          }          n->data=v;          N->left=create_ ();          N->right=create_ ();          return n;     }}

  

/** Two fork Tree Establishment method two *2014.12.17*/void Create_ (root *t) {    char v;    scanf ("%c", &v);    if (v== ')    {        *t=null;    }    else {                  if (! ( *t= (node*) malloc (sizeof (node)))          {              printf ("Failed to allocate memory");              Exit (1);          }         (*t)->data=v;         Create_ (& (*t)->left);         Create_ (& (*t)->right);    }    return;}

  

Data structure on-machine examination (Kai shen Version)//modified binary tree

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.