It checks that two linked lists contain the same values.
Obviously, if one list is shorter, they are not identical (point B).
Note: I think using here break
/return
would be a better choice, it makes the code more readable.
Note2: as noted on the comments, those should be logical operators. It works as it is, but it's a bit confusing.
Note3: You could move the test before the loop inside the loop (while(1)
), this would eliminate the need for the test at the end of the loop.
This is just an ugly code, it should be about 5 lines of code, not a dozen...
bool sameValues (chainCell *x, chainCell *y)
{
while(1) {
if (!x && !y) return true;
if (!x || !y) return false;
if (x->data != y->data) return false;
x = x->next;
y = y->next;
}
return false; //this is just to suppress compiler warning.
};