If the popped node is right child of top , then remove the top as well . Left child of the top must have processed before .
while ( st . Count != 0 && st . Peek ( ) . right == root ) { root = st . Peek ( ) ; st . Pop ( ) ; } }