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