https://ide.codingblocks.com/s/62990
one test case passed 2 wrong answer
you forget to put endl if right child exist. i have corrected your code you can refer this