aim for a more robust method that calculates in a single trip the even and odd levels. Output 2 2 / OR / Input : 1 / 5 8 / /.

Given a, binary Tree having odd and even elements, sink all its odd valued nodes such that no node with odd value could be parent of node with even value.

There can be multiple outputs for a given tree, we need to print one of them.

It is always possible to convert a tree (Note that a node with even.

If there is an node with an odd value containing subnodes with even values, the subnodes will not be counted in your code. MyBB at Computer Science is now closed in favour of a new bulletin board system. You can still read the old postings, but we are switching to a new bulletin board system.

Null) enqueue(current- right nodesInLevel-; currentLevel; /Calculates difference between oddLevel and evenLevel diffOddEven abs(oddLevel - evenLevel return diffOddEven; int video editing job work from home main /Add nodes to the binary tree root createNode(1 root- left createNode(2 root- right createNode(3 root- left- left createNode(4 root- right- left createNode(5 root- right- right createNode(6. If both children have odd values, that means that all its descendants are odd. Number of elements in queue nodesInLevel ze while(nodesInLevel 0) Node current move /Checks if currentLevel is even or not. Right.right Node(6 #Display the difference between sum of odd level and even level nodes print Difference between sum of odd level and even level nodes: " str(bt. Right.right new Node(6 /Display the difference between sum of odd level and even level nodes intln Difference between sum of odd level and even level nodes: ". Please use ideone or, c Shell or any other online compiler link to post code in comments. The required difference is ( ) ( ) -4. Below is C implementation of the idea.

Pop(0 #Checks if currentLevel is even or not. Right null; public class DiffOddEven T /Represent the root of binary tree public Node T root; T treeArray; int index 0; public DiffOddEven root null; /difference will calculate the difference between sum of odd and even levels of binary tree public int difference int oddLevel. Data; else /If level is odd, add nodes's to variable oddLevel oddLevel current.