I need help!!
There is a question where I have to create a program to perform Inorder on the following data:
60, 40, 80, 22, 55, 99
I think I got the right coding for Inorder. But I have problem in inserting the data. I got the InsertTree function from a book.But the function has 3 parameters. Do I need key in this function?
Urgent help needed. Thanks.
#include<stdio.h>
struct TreeNode
{
int Data;
struct TreeNode *Left, *Right;
};
typedef struct TreeNode TreePointer;
void InsertTree(TreePointer Root,Datarecord rec,int key);
void Inorder(TreePointer Root);
void main()
{
TreePointer Root;
/*60,40,80,22,55,99*/
printf("Enter number");
scanf("%d", num);
InsertTree(?;?;?);
Inorder(num);
getch();
}
void Inorder(TreePointer Root)
{
if(Root!=NULL)
{
Inorder(Root->Left);
printf("%d ", Root->Data);
Inorder(Root->Right);
}
}
void InsertTree(TreePointer Root,Datarecord rec,int key)
{
if (Root == NULL)
{
Root = (TreePointer)malloc(sizeof(TreeNode));
Root->Key = Key;
Root->Data = rec;
Root->Left = NULL;
Root->Right = NULL;
}
else
{
if (Key < Root->Key)
InsertTree(Root->Left,rec,Key);
else
InsertTree(Root->Right,rec,Key);
}
}



LinkBack URL
About LinkBacks


