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.
This is a discussion on Stack within the C Programming forums, part of the General Programming Boards category; How can I use a stack to reverse the order of a string. If I have "abcde" I want to ...
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