Question: Write an algorithm to print a binary tree level wise and that too from leaves to root. Also only one queue and one stack can be used for the purpose.

Solution: 1. Start from root and enqueue to the queue.
2. Dequeue an element and push it to the stack.
3. Enqueue the children from the dequeued node(from step 2).
4. Repeat step 2 and 3 until you reach the leaves.
5. Now print the stack by popping elements until it gets empty.

BreadthOrderTraversalReverse(BinaryTree binaryTree)
{
Queue queue;
queue.Enqueue(binaryTree.Root);
while(Queue.Size > 0)
{
Node n = GetFirstNodeInQueue();

queue.Enqueue(n.RightChild); //Enqueue if exists
queue.Enqueue(n.LeftChild); //Enqueue if exists
stack.push() = queue.Dequeue(); //Visit
}

while(!isEmpty(stack))
print(stack.pop);

}