for printing the nodes in order from right to left
while ( Q . length != 0 ) { temp = Q [ 0 ] ; Q . shift ( ) ; document . write ( temp . data + " " ) ; if ( dir == LEFT ) { if ( temp . left != null ) S . push ( temp . left ) ; if ( temp . right != null ) S . push ( temp . right ) ; } else { if ( temp . right != null ) S . push ( temp . right ) ; if ( temp . left != null ) S . push ( temp . left ) ; } } document . write ( " " ) ;