Please check my code
Binary Tree top view
@minal.251298,
https://ide.codingblocks.com/s/225758 corrected code.
Your code was correct but incase there was a stray " " (space) in the inputs, your code won’t take input the correct way. I have modified the input approach a little. Your topView method was correct.