You are on page 1of 2

#include <stdio.

h>
#include <stdlib.h>

struct node {
char item;
struct node* left;
struct node* right;
};

void inorderTraversal(struct node* root,int length,int count) {


if (root==NULL) return ;
while(count != length+1)
{
root=root->left;
if(count == length)
{
printf(" %c ", root->item);

}
count++;
}

}
struct node* createNode(value) {
struct node* newNode = malloc(sizeof(struct node));
newNode->item = value;
newNode->left = NULL;
newNode->right = NULL;

return newNode;
}

struct node* insertLeft(struct node* root, char value) {


root->left = createNode(value);
return root->left;
}

struct node* insertRight(struct node* root, char value) {


root->right = createNode(value);
return root->right;
}

int maxDepth(struct node* node)


{
if (node == NULL)
return -1;
else
{
/* compute the depth of each subtree */
int lDepth = maxDepth(node->left);
return(lDepth + 1);
}
}

int main() {
struct node* root = createNode(grammer[0][1]);
insertLeft(root, 'T');
insertRight(root, 'a' );
insertLeft(root->left, 'b');
insertRight(root->left, 'c');
printf("%d\n",maxDepth(root));
printf("Inorder traversal \n");
printf("First of S : ");
inorderTraversal(root,maxDepth(root),1);
printf("\nFirst of T : ");
inorderTraversal(root->left,maxDepth(root->left),1);

insertLeft(root->left, 'b');
insertRight(root->left, 'c');
printf("%d\n",maxDepth(root));
printf("Inorder traversal \n");
printf("First of S : ");
inorderTraversal(root,maxDepth(root),1);
printf("\nFirst of T : ");
inorderTraversal(root->left,maxDepth(root->left),1);

You might also like