I have to add 2 polynomial equations. Each are stored in linked lists. eq_1 and eq_2 linklists are added and the total is stored in eq_1 linklist.
But the problem is when im trying to add both equations, the 2nd for loop(eq_2) is looping once only. I mean when eq_1 loops for the 2nd time eq_2 doesn't loop anymore. I used 2 integer counters to check the loop running times. Now I want to know how I can run the second loop for every time when loop 1 is looped.
Thanks :)
for( ; eq_1 != nil; eq_1 = eq_1->tail ) { //follow up each nodes of eq1
for( ; eq_2 != nil; eq_2 = eq_2->tail ) {
if(eq_1->power==eq_2->power){ //if both have equal power then add up both coefficients
newnode(eq_1,(eq_1->coefficient+eq_2->coefficient),eq_1->power);//add to eq1
}
else { //When both aren't same add up both to sum link list
eq1(eq_2->power,eq_2->coefficient,nil); //add it to eq1
}
}
}