The following example shows that the if condition is incorrect ~~~
# Define ERROR 0
# Define OK 1
Typedef int Status;
Typedef int ElemType;
Typedef struct LNode {
ElemType data;
Struct LNode * next;
} LNode, * LinkList;
/* L is the header pointer of a single-chain table at the header node */
/* When the I-th element exists, the value is assigned to e and OK is returned. Otherwise, ERROR */is returned */
Status GetElem (LinkList L, int I, ElemType & e)
{
LinkList p = L-> next;
Int j = 1; // counter
While (p & j <I) // find the I-th Node
{
P = p-> next ;//
+ + J; // p always points to the j Node
}
If (! P | j> I) // there are two possibilities that cannot be found, I .e., I is not in the range: I <1 | j <I because if the result of the j traversal chain table is only two results:
Return ERROR; // If I is obtained or I is not obtained, if I is not obtained, the counter j must be the table length; otherwise, j = I,
E = p-> data; // so I think this if condition is incorrect. The two conditions may refer to one case, that is, traversing to the end of the table and not finding it.
Return OK;
}
This article is from the "Fire Bamboo" blog