Question: Please fix the function code blow: in the for loop, I want end the loop when i and j both equal to 0. And when

Please fix the function code blow:

in the for loop, I want end the loop when i and j both equal to 0. And when only one of them equal to 0 the loop will continue running.

I use i!=0&&j!=0 for the condition, but the loop ends when one of i or j equal to 0, it should continue running until both of them equal to 0. I don't know what's wrong with my for loop function. The code is blew:

for(i=len1,j=len2;i!=0&&j!=0;)

{

if((min[i][j]==min[i-1][j-1])&&(word1[i-1]==word2[j-1])) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]=word2[j-1]; cost[max(i,j)-1]='.'; i--;j--; } else if(min[i][j]==min[i-1][j-1]+1) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]=word2[j-1]; i--;j--; }

else if(min[i][j]==min[i-1][j]+1) { path1[max(i,j)-1]=word1[i-1]; path2[max(i,j)-1]='-'; i--; } else if(min[i][j]==min[i][j-1]+1) { path1[max(i,j)-1]='-'; path2[max(i,j)-1]=word2[j-1]; j--; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!