Sorry for the confusing title. Basically I have a line which I read from a file that gets stored as an array stack of characters that reads as follows:
Nn<-<-<-<-No <-w iz<-sthe<-<-<- the time.
Where the top of the stack is the '.', and the bottom is the 'N' respectively.
I need to write a function that processes the line by taking each "<-" as a 'backspace' and subsequently rewriting the line so that it would turn into this
Now is the time.
I have access to the typical stack functions: pop, push, and peek. I'm trying to come up with an algorithm for it but I'm having difficulty coming up with something that works with any number of consecutive backspaces! As you can see one backspace is simple enough, but any more than one and I'm in trouble!
void processLine(stack<char> &array, int linelength)
{
char discardvar;
char catchvar;
for (int i = 0; i < linelength; i++)
{
array.pop(catchvar);
if (catchvar == '-') //if there is a '-', pop off the '<' and the letter its erasing
{
array.pop(discardvar);
array.pop(discardvar);
}
else if (catchvar == '<')
{
}
else
array.push(catchvar); //placeholder, didn't think of way to reconstruct line yet
}
}
If any additional information is needed that I haven't provided, please let me know! Thanks in advance!