Given a list of numbers representing nodes of a Binary Tree along with "null" which represents NULL, here we create the binary tree and check if it is a full binary tree in the C++ language
Here firstly we are building the tree in which we take the input and if the list has null as input we will send the max_int as the data. Now we create the node with the data in the list and start creating the tree by checking if the left part is free or the right part is free and if the node created is not by int_max (i.e) null, then the iterator will be updated in the queue and after the right part of the node present is updated the node will be removed from the queue.
After the tree is created we will update the int_max, NULL parts with the NULL iterator. For all the above processes the initializing of nodes is done and the root is defined and for creating the nodes with the data are created using malloc.
For checking if the created tree is a full binary tree or not we will start from the root and if both parts do not have null we continue to transverse through the tree till the end by recursion and if the root is only null we will return true else if both left and right nodes are null then also it will return true else if only one of them is null it will return false.
Submitted by Jayaditya Jakkam (Jayaditya)
Download packets of source code on Coders Packet