Clue two fork tree ? What is a clue two fork tree? A binary tree of the left and right leaves node, note is the leaf node, the leaves are usually empty nodes and points, in order to effectively use the left and left nodes, we will point to his predecessor, the right node point to his successor!:
Create a Clue two fork tree, traverse the Clue two tree code:
#include <stdio.h> #include <stdlib.h>typedef char elemtype;//thread store flag bit//link (0) indicates pointer to left and right child//thread (1) Indicates a clue that points to the predecessor of the typedef enum {link,thread} pointertag;typedef struct Bithrnode{char data;struct bithrnode *lchild,*rchild; Pointertag Ltag; Pointertag Rtag;} bithrnode,*bithrtree;//creates a binary tree that contracts the user to enter data in the form of a pre-order traversal void Createbithrtree (Bithrtree *t) {char c;scanf ("%c", &c);// User input if (' ==c ') {*t=null;} else{*t= (bithrnode*) malloc (sizeof (Bithrnode));(*t)->data=c; (*t)->ltag=link; (*t)->rtag=link; Createbithrtree (& (*t)->lchild);//Recursive Call Createbithrtree (& (*t)->rchild);//Recursive call}}//mid-order traverse Bithrtree pre;//points to the previous visited node inthreading (Bithrtree t) {if (t) {inthreading (t->lchild);//recursive Left child threaded if (! T->lchild) {t->ltag=thread; T->lchild=pre;} if (!pre->rchild) {pre->rtag=thread;pre->rchild=t;} Pre=t;inthreading (t->rchild);//recursive Right child threaded}}void inorderthreading (bithrtree *p,bithrtree T) {*p= (BiThrTree) malloc ( sizeof (Bithrnode));(*p)->ltag=link;//set to Connection point (*P)->rtag=thread;//set as Thread (*P)->RChild=*p;//Initialize to point to yourself if (! T) {(*p)->lchild=*p;} else{(*p)->lchild=t;//its left node points to the root of the tree pre=*p;//initializes the previous node inthreading (T);//to lead//As a result of the lead, the pre will change and lead to a ring. See Figure 1pre->rchild=*p;pre->rtag=thread; (*p)->rchild=pre;}} void visit (char data) {printf ("%c", data);} void Inordertraverse (Bithrtree T) {Bithrtree p;p=t->lchild;//left dial hand tree while (p!=t) {//determines if the same node while (P->ltag==link) {p =p->lchild;} Visit (p->data);//Find the last node by clues while (P->rtag==thread && p->rchild!=t) {p=p->rchild;visit (p-> data);} P=p->rchild;}} int main () {Bithrtree p,t=null; Createbithrtree (T);//Create two-fork Tree inorderthreading (&p,t);//Thread two-tree printf ("Middle-order traversal of the Clue Tree:"); Inordertraverse (P);p rintf ("\ n") ;}
Figure 1
Clue Two fork Tree