Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct Tnode
- {
- int data;
- struct Tnode *left;
- struct Tnode *right;
- };
- struct Qnode
- {
- struct Tnode *pt_t;
- struct Qnode *next;
- };
- struct Qnode q;
- struct Qnode *FRONT, *REAR;
- void deque()
- {
- struct Qnode *tmp;
- tmp = FRONT;
- FRONT = FRONT->next;
- free(tmp);
- }
- void enqueue(struct Tnode *ele)
- {
- struct Qnode *tmp;
- tmp->pt_t = ele;
- REAR->next = tmp;
- REAR = REAR->next;
- }
- struct Tnode* newNode(struct Tnode *tp)
- {
- struct Tnode tmp;
- /*tmp.data = NULL;
- tmp.left = NULL;
- tmp.right = NULL;*/
- tp = &tmp;
- return tp;
- }
- void create_tree(int ele)
- {
- struct Tnode *t;
- FRONT->pt_t->data=ele;
- FRONT->pt_t->left=newNode(t);
- FRONT->pt_t->right=newNode(t);
- enqueue(FRONT->pt_t->left);
- enqueue(FRONT->pt_t->right);
- deque();
- }
- void main()
- {
- struct Tnode *t;
- printf("\nInitializing....\n");
- int ele,ch;
- FRONT = REAR = &q;
- q.pt_t=newNode(t);
- q.next=NULL;
- printf("\nProgram is ready for use!\n");
- while(1)
- {
- printf("\nWant to enter data to tree(1/0)?\n");
- scanf("%d",&ch);
- if(ch==1)
- {
- printf("\nEnter element:\n");
- scanf("%d",&ele);
- create_tree(ele);
- }
- else if(ch==0)
- exit(0);
- else
- printf("\nInvalid choice!\n");
- }
- }
Add Comment
Please, Sign In to add comment