2

I'm running into a simple problem:

    string minEditOperations(vector<vector<int>> DPTable, string firstString, string secondString)
{
    //second string is what first string needs to be changed into, the DPTable function is    flipped
     int rowIterator = firstString.size() , columnIterator = secondString.size();

     string output;

while (rowIterator > 0 && columnIterator > 0)
{
    if (firstString[rowIterator - 1] == secondString[columnIterator - 1])
    {
            //Keep
            columnIterator--;
            rowIterator--;
            output = '^' + output;
    }
    else
    {
        //Calculate the different values
        int mincompare = min(DPTable[rowIterator - 1][columnIterator - 1], min(DPTable[rowIterator][columnIterator - 1], DPTable[rowIterator - 1][columnIterator]));

        if (DPTable[rowIterator - 1][columnIterator - 1] == mincompare)
        {
            output = "/" + firstString[rowIterator] + output;
        }
        else if (DPTable[rowIterator -1][columnIterator] == mincompare)
        {
            output = "-" + output;
        }
        else
        {
            //Right
            //Insert
            output = "+" + firstString[columnIterator] + output;
            columnIterator--;
        }

    }

}
return output;
}

I am attempting to "prepend" to a string, however whenever the code executes, the output string never changes.

 output = "+" + firstString[columnIterator] + output; 

Can anyone shed some light on this?

1
  • 2
    Can you post more of your code please? It's hard to understand with just that line. Commented Apr 21, 2014 at 1:55

1 Answer 1

2

The problem seems to arise from attempting to add strings to char values (since firstString[rowIterator] is a char).

Try something like this:

output = "/" + string(1, firstString[rowIterator]) + output;

That basically creates a string of length 1 from a char.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.