help me to ass something

after we create this code additional functions to be needed to pass this code!...

can someone help me! ..
NOTE: its in additional functions:


/// Implementing Binary Tree Using Linked List Structure ///

# include <stdio.h>
# include <conio.h>
# include <alloc.h>
# include <stdlib.h>

struct tnode {
int data;
struct tnode *lchild;
struct tnode *rchild;
};

struct tnode *NewNode(int);
struct tnode *insert(struct tnode *, int);
int size(struct tnode *);
void inorder(struct tnode *);
void preorder(struct tnode *);
void postorder(struct tnode *);
int lookup(struct tnode *, int);

/* additional functions needed to be added are the following
1. deleting a node in a BT -> BST deletion of a node
2. cntSubtree(tree) -> retrieves the number of subtrees in a BT
3. isParent(node_value) -> returns 1/0 (Yes/No) if node in a BT is a parent node
4. minValue(tree) -> returns the minimum node value in a BT
5. pathLength(tree,node) -> returns the length of the path from root to node
*/

void main() {
int num;
char choice, ans;
//char *str1="world", *str2="world";
struct tnode *p; /* p can be said as the root ptr */
p=NULL;
/* Printing the menu */

//printf("%s < %s is %d", str1, str2, strcmp(str1,str2));
//getch();
do {
clrscr();
printf("PROGRAM TO IMPLEMENT BINARY TREE USING LINKED LIST STRUCTURE");
printf("\n=====================================");
printf("\n1.Insert A Node");
printf("\n2.Size of the Tree");
printf("\n3.Inorder Traversal");
printf("\n4.Preorder Traversal");
printf("\n5.Postorder Traversal");
printf("\n6.Search a Node Value");
printf("\n7.Exit");

oper:
gotoxy(1,15);
printf(" ");
gotoxy(1,11);
printf("\n\nEnter ur Choice : ");
choice=getch();

switch(choice) {
case '1':
do {
printf("\nEnter any number : ");
scanf("%d",&num);
p=insert(p,num);
printf("Enter more (y/n) :");
fflush(stdin);
ans=getchar();
} while(ans !='n');
break;
case '2':
printf("\nSize of the Tree : %d", size(p));
getch();
break;
case '3':
printf("\nInorder Traversal : ");
inorder(p);
getch();
break;
case '4':
printf("\nPreorder Traversal : ");
preorder(p);
getch();
break;
case '5':
printf("\nPostorder Traversal : ");
postorder(p);
getch();
break;
case '6':
printf("\nLook for a node value : ");
scanf("%d",&num);
if(lookup(p,num))
printf("Node Value Found.");
else
printf("Node Value Not Found.");
getch();
break;
case '7':
printf("\n\nQuiting.......");
getch();
exit(0);
break;
case '8':
printf("\nMaximum Depth : %d", maxDepth(p));
getch();
break;
case 'a':
printf("Minimum Value : %d", minValue(p));
getch();
break;
case 'b':
printf("Maximum Value : %d", maxValue(p));
getch();
break;
default:
gotoxy(1,15);printf("Invalid choice.Please Enter Correct Choice");
getch();
goto oper;
}
} while(choice !=7);
}

struct tnode *NewNode (int data) {
struct tnode *node = (struct tnode *) malloc(sizeof(struct tnode));
node->data=data;
node->lchild = NULL;
node->rchild = NULL;

return node;
}

struct tnode *insert(struct tnode *node, int data) {
// 1. If the tree is empty, return a new, single node
if (node == NULL)
return NewNode(data);
else {
// 2. Otherwise, recur down the tree
if (data < node->data)
node->lchild = insert(node->lchild, data);
else if (data > node->data)
node->rchild = insert (node->rchild, data);

return node;
}
}

void preorder(struct tnode *node) {
if(node!=NULL) {
printf("%4d",node->data);
preorder(node->lchild);
preorder(node->rchild);
}
}

void inorder(struct tnode *node) {
if(node!=NULL) {
inorder(node->lchild);
printf("%4d",node->data);
inorder(node->rchild);
}
}

void postorder(struct tnode *node) {
if(node!=NULL) {
postorder(node->lchild);
postorder(node->rchild);
printf("%4d",node->data);
}
}

int size(struct tnode *node) {
if(node==NULL)
return 0;
else
return size(node->lchild) + 1 + size(node->rchild);
}

int lookup(struct tnode *node, int target) {
// 1. Base Case -> Empty Tree
// in that case, the target is not foundso return false
if (node == NULL)
return 0;
else {
// 2. see if found here
if (target == node->data)
return 1;
else {
// 3. otherwise recur down the correct subtree
if (target < node->data)
return lookup(node->lchild, target);
else return lookup(node->rchild, target);
}
}
}
The functions
1
2
3
4
5
clrscr()
gotoxy()
maxDepth()
minValue()
maxValue()

are not defined in your program.
You must either include an external library which provides them, or you must write them.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Topic archived. No new replies allowed.