Given a file, the task is to print as well as store the lines of that file in reverse order using Stack.
Input : I am new to this world of Python. Output : Python. world of new to this I am Input : 1 2 3 4 5 Output : 5 4 3 2 1
- Create an empty stack.
- One by one push every line of the file to the stack.
- One by one pop each line from the stack and put them back to the file.
Below is the implementation.
Ths is a World of Geeks. Welcome to GeeksforGeeks.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.