Lab 10 Data Structure 15 December
Lab 10 Data Structure 15 December
Deletion a node:
In deletion node we have to tackle three cases that is if the tree have no child one child or two child for
each of this we have to write program for this I use if statement that would check if root is null or not if
the data we want to delete is greater than root data then it delete the element the right data of tree
else if the data we want to delete is less then it will delete the left element. For one child I use if
statement that will check if the left and right is null it means the tree have one child and it would be
deleted for one child I also use if statement that would check both left and right data and for two child I
also use if statement that would check both left and right if both have data it mean it have two child.
2. Node search
in this task we have write program that would search specific element for this I use if statement that
would compare the root element and the element we want to search if the root element is equal to the
search element then we would return the element again I use if statement that would check if the key
element is greater than root data then it will search in the right of search tree else it will search in right
of search tree and in this way the element is found.
Program:
Output:
SEARCH 46
Next I search for 100 as 100 is not in tree it display message element not found.
In pre-order the root element is first printed then the element on left and the element right of root. For this
I use if statement that check the root is empty or not then I print statement that print root element then the
element on left and then or right.
Output:
POST ORDER:
In post order the element on the left of tree is print first then the right element is printed and the root
element is print last therefore I use if statement that check if the root is empty or not and in else
statement I print the left element then the right element and then the root element is printed.
Post order:
OUTPUT:
POST LAB TASKS
SAVE POST ORDER:
In this task we have save the post order therefore I use if statement
that would check if the root is empty or not and then I call save
function that would first save the left and then the right and the root
element.
_________________________________________________________