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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started