My previous post was just some context as to 'what the user sees'. Your instructions deal heavily with 'how the code is written'. The code uses a stack to create the behavior that the user sees.
Suppose your user starts with some text like this.
She sees that she needs to remove one of the 'p' characters. To do this, she will inject a '#' sign after the letter she wants to remove. Let's say she decides that the second 'p' is getting cut.
Now this text is ready to be fed to your program. Your program will go character by character through the input string, enforcing one of four rules:
1. Pop the stack if this character is '#'.
2. Read the next character and put it on the stack if this character is '$'
3. Pop the stack over and over until a ' ' <space> is found if this character is '@'.
4. Push this character onto the stack if it isn't one of the special characters.
Here's what your stack looks like as you iterate over the input string.
p
p p
a a a
H H H H
---------------------------------------------------------
(0) (1) (2) (3) : iteration
H a p p : current character
4 4 4 4 : rule applied
|
Nothing too surprising for the first four characters. None of them are special, so Rule 4 applies: Push the character onto the stack.
The next character, however, is special. It is the '#' sign, which means Rule 1 applies: Pop the stack.
p
p p p
a a a a
H H H H H
---------------------------------------------------------
(0) (1) (2) (3) (4) : iteration
H a p p # : current character
4 4 4 4 1 : rule applied
|
Since this is a simple example, and that's the only special character in the string, I can quickly show you how the rest of the iteration goes.
y
p p p
p p p p p
a a a a a a
H H H H H H H
---------------------------------------------------------
(0) (1) (2) (3) (4) (5) (6) : iteration
H a p p # p y : current character
4 4 4 4 1 4 4 : rule applied
|
If you were to pop and print everything on your stack, you would see "yppaH". That's where the reversal will come into play.