CSE 220 (Data structure)

Lab Assignment 8

 

 

 

Declaration of a binary tree:-

 

struct TreeNode{

   int Data;

   struct TreeNode *Left,*Right;

};

 

typedef struct TreeNode *TreePointer;

Variable Declaration

TreePointer Root;

 

 

void InsertTree(TreePointer &Root, TreePointer

                              NewNode)

{

if(Root==NULL)

{

      Root = NewNode;

         Root->Left = NULL;

      Root->Right = NULL;

}

else

{

if(NewNode->Key < Root->Key)

InsertTree(Root->Left,NewNode);

else

InsertTree(Root->Right,NewNode);

}

}

 

 

Your task:

 

  1. Make a function  [TreePointer  MakeNode(int data) ](which will take input of an integer and makes a new node (TreePointer type) and returns
  2. From main function call the void InsertTree function 5 times to insert 5,10,15,20,8 data.

[For example, InsertTree(Root,MakeNode(5)); ]

 

3. Make a function PrintLeft(TreePointer Root) which will print only left children of Root until NULL reaches.