General C program
The following code;
typedef struct chainCell{
int data;
struct chainCell* next;
} chainCell;
bool sameValues (chainCell *x, chainCell *y)
{
if ((x == NULL) & (y == NULL)) return true;
if ((x == NULL) | (y == NULL)) return false;
bool same = true;
chainCell *xp = x, *yp = y; // scan pointers
while ((xp != NULL) & (same == true)) // point A
{
if (xp->data != yp->data) same = false;
xp = xp->next;
yp = yp->next;
if (((xp == NULL) & (yp != NULL)) // point B
| ((xp != NULL) & (yp == NULL)))
same = false;
};
return same;
};
I am very confused as to why the loop control contains (same == true) ?
Also what is the purpose of the if statement at Point B? I'm unsure of
what the Boolean expression is checking for?
Any help for further understanding would be appreciated!
No comments:
Post a Comment