Printing path using stack