PRACTICE PROGRAM: 1) Write a C program to find all the ancestors or descendent of a given node in a binary tree. ANS: #include <conio.h> #include <stdlib.h> #include <stdio.h> #define MAX 100 typedef struct tree { int data; struct tree *left, *right; } TREE; int isEmpty(TREE *t) { return (t == NULL) ? 1 : 0; } typedef struct queue { TREE *data[MAX]; int front, rear; } QUEUE; typedef struct stack { TREE *data[MAX]; int top; } STACK; int isEmptyStack(STACK *s) { return (s->top == -1) ? 1 : 0; } int isFullStack(STACK *s) { return (s->top == MAX - 1) ? 1 : 0; } void push(STACK *s, TREE *t) { if (isFullStack(s)) { printf("\n Stack is Full!"); } else { s->top++; s->data[s->top] =...
Comments
Post a Comment
Enter comment here!