Find the list

Even if we know that you are looking for is the i-th node, we can not reach directly, because the node is not stored in the order, we can only start from scratch pointers, one by one along the chain domain next node down the search until the search until ai.

 //查找第i个节点 
int FindElem(LinkList &L, int &e, int i)
{
	LNode *p;
 	p = L->next; //p指向首节点
	int j =  1;   // j表示第几个节点 
 	if (i < 1)
		return 0;
	while (p != NULL && j < i)   //p后无节点了或者找到第i个节点 
	{
		p = p->next;
		j++;
	}
	if (p == NULL)
		return 0;
	e = p->date;
		
	return 1;
}
Published 24 original articles · won praise 0 · Views 141

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105238232