List of Single-Chain tables

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.