For printing nodes from right to left , push the nodes to stack instead of printing them .
else { if ( temp . right != null ) Q . push ( temp . right ) ; if ( temp . left != null ) Q . push ( temp . left ) ; } } document . write ( " " ) ;