How can I use a stack to reverse the order of a string.
If I have "abcde" I want to print the reverse "edcba". But I want a stack program to do the reverse action.
I need some logical guidance. I do have a working stack program.
How can I use a stack to reverse the order of a string.
If I have "abcde" I want to print the reverse "edcba". But I want a stack program to do the reverse action.
I need some logical guidance. I do have a working stack program.
A stack works according to the LIFO (last in - first out) principe.
Assume data is: abcde. If you push 'a' first on the stack, than the stack looks like:
e - top
d
c
b
a - bottom
Now you pop 'e' first from the stack. So popping all data from the stack results in:
edcba