2.13② 试写一算法在带头结点的单链表结构上实现线性表操作
Locate(L,x)。
实现下列函数:
LinkList Locate(LinkList L, ElemType x);
// If 'x' in the linked list whose head node is pointed
// by 'L', then return pointer pointing node 'x',
// otherwise return 'NULL'
单链表类型定义如下:
typedef struct LNode {
ElemType data;
struct LNode *next;
} LNode, *LinkList;
LinkList Locate(LinkList &L, ElemType x)
// If 'x' in the linked list whose head node is pointed
// by 'L', then return pointer ha pointing node 'x',
// otherwise return 'NULL'
{
LinkList p;
for(p=L->next;p&&p->data!=x;p=p->next);
return p;
}