Assignment HELP! (Using Stacks)

Posted 03 June 2014 - 08:11 PM

I have a programming assignment I'm stuck on. The assignment is to create a SmartString class that implements a SmartStringInterface class (created by professor) and implements a few methods. We are basically taking a string and then taking various substrings and inserting, deleting them and undoing changes as well. Here are the methods in the interface to use along with the parameters.

The Undo is supposed to be able to be called multiple times (to be tested using a driver program that we must create) but the part that's got me is that the changes are only supposed to be stored. Currently, I am storing the "new" string after each change onto a stack, so that undo can just pop off the stack and it will revert to the previous string. Professor said that was wrong, so I don't know how to do it. Here is what I have so far (some of the code we have is using default StackADT stuff from our book, so if you need that I can post as well. You can see in the undo method where I currently save the string. We can use multiple stacks if needed, but the less the better. Must use at least 1. The exception code is already coded for us in another file also. I am only having to code these methods and the driver to test.

Basically, every call toString, you apply all the current changes. This means you have to unwind the stack to get to the first operation. Recursion would be helpful for this. Don't forget to rewind the stack. Yes, a stack is a crappy choice for this. Your instructor is torturing you and clearly has some very specific process in mind.

Ignore the changes part since that is how I was previously storing the changes with the resulting string into the stack, but that's the part the professor said was wrong, so that's where I'm completely list is the undo and storing the actual changes. If I know how to store the changes, I think the undo will be a bit easier. Looking at your example confused me, as I don't understand part of it nor how I can apply that to mine