Print the nodes at odd levels of a tree | Recursive C # program to print odd level nodes ; If empty tree ; If current node is of odd level ; Recur for children with isOdd switched . ; Utility method to create a node ; Driver code
using System ; public class GfG { public class Node { public int data ; public Node left , right ; } public static void printOddNodes ( Node root , bool isOdd ) { if ( root == null ) { return ; } if ( isOdd == true ) { Console . Write ( root . data + " ▁ " ) ; } printOddNodes ( root . left , ! isOdd ) ; printOddNodes ( root . right , ! isOdd ) ; } public static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void Main ( string [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; printOddNodes ( root , true ) ; } }