void pretrav(nodeptr root){ if(root!=NULL){ printf("%d\n",root->data); pretrav(root->left); pretrav(root->right); } }
void pretrav(NODEPTR t){ if(t!=NULL){ printf("%d\n",t->key); pretrav(t->left); pretrav(t->right); } }
void pretrav(struct node*r) /* FUNCTION FOR RECURSIVE PRE-ORDER TRAVERSAL */ { if(r!=NULL) { printf("%s\t",r->data); pretrav(r->left); pretrav(r->right); } }
void traversal(NODEPTR p){ int ch; printline('*'); while(1){ printf("\nEnter the choice\n1.pretraversal\n2.posttraversal\n3.inorder\n4.return"); scanf("%d",&ch); switch(ch){ case 1: pretrav(p);break; case 2: posttrav(p);break; case 3: intrav(p);break; case 4: break; default: printf("Hi i m default"); break; }/*end of switch*/ } }/*end of traversal*/
int main(){ int data = -1; int label = 0; printf("Provide data for the root node\n"); scanf("%d",&data); nodeptr root = getnode(label,data); createTree(root); printf("\n=====================Preorder Traversal====================\n"); pretrav(root); return 0; }
void main() { int choice,c,d,flag; char temp='N',temp1[15]; root=NULL; do { clrscr(); printf("\n\n\n\t\t ***** THE CHOICE - MENU IS *****"); printf("\n\n\n\t\t1> ENTER"); printf("\n\t\t2>TRAVERSE"); printf("\n\t\t3>DISPLAY"); printf("\n\t\t4>EXIT"); printf("\n\n\t\t ENTER YOUR CHOICE :"); scanf("%d",&choice); switch(choice) { case 1: root= NULL; /* INSERTION OF NODE */ root->left=NULL; root->right=NULL; do { s= (struct node*)malloc (sizeof(struct node)); s->left=NULL; s->right=NULL; printf("\n Enter The Data:"); scanf("%s",&s->data); cont++; if(root==NULL) root=s; //ASSIGNING VALUE TO ROOT NODE else insert(root,s); fflush(stdin); printf("\n Enter More Elements(Y/N):"); scanf("%c",&temp); }while(temp=='y'||temp=='Y'); break; case 2: do { clrscr(); printf("\n\n\n\n\t\t **** THE CHOICE - MENU IS ****"); printf("\n\n\n\n\t\t 1.RECURSIVE TRAVERSING\n\n\t\t 2.NON-RECURSIVE TRAVERSING\n\n\t\t 3.EXIT"); printf("\n\n\t\tEnter Your Choice:"); scanf("%d",&d); switch(d) { case 1: clrscr(); do { clrscr(); printf("\n\n\n\n\t\t **** THE CHOICE - MENU IS ****" ); printf("\n\n\n\t\t1.PREORDER\n\t\t2.INORDER\n\t\t3.POST-ORDER\n\t\t4.Exit"); printf("\n\n\tEnter Your Choice:"); scanf("%d",&c); if(root==NULL) printf("\n\n Tree Not Started Yet !!"); else { switch(c) { case 1: //CALLING OF RECURSIVE FUNCTIONS pretrav(root); break; case 2: intrav(root); break; case 3: posttrav(root); break; } printf("\n Press Any Key To Continue !!!"); getch(); } }while(c!=4); break; case 2: clrscr(); do { clrscr(); printf("\n\n\n\n\t\t **** THE CHOICE MENU IS ****"); printf("\n\n\n\t\t1.PREORDER\n\t\t2.INORDER\n\t\t3.POST-ORDER\n\t\t4.Exit"); printf("\n\n\tEnter Your Choice:"); scanf("%d",&c); if(root==NULL) /* TREE EMPTY CONDITION */ printf("\n\n Tree Not Started Yet !!"); else { switch(c) { case 1: npretrav(root); //CALLING OF NON-RECURSIVE break; //FUNCTIONS case 2: nintrav(root); break; case 3: npostrav(root); break; } printf("\n Press Any Key To Continue !!!"); getch(); } }while(c!=4); break; } }while(d!=3); break; case 3: if(root==NULL) printf("\n THE TREE IS EMPTY "); else { initgraph(&gd,&gm,"d:\\tc"); //CALLING FUNCTION FOR DISPLAY display(root,1,getmaxx()+1,15,1); // 640 is the getmaxx getch(); closegraph(); } break; } }while(choice!=4); }