我们还没有学到链表的创建,为了方便大家在编译器调试程序,把函数题中建表的代码发给大家参考。
#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LinkList Create();/* 细节在此不表 */
int main()
{
ElemType e;
LinkList L = Create();
scanf("%d",&e);
printf("%d\n", Locate(L,e));
return 0;
}
LinkList Create()
{
LinkList L,r,p;
ElemType e;
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
r = L;
scanf("%d",&e);
while(e!=-1)
{
p = (LinkList)malloc(sizeof(LNode));
p->data = e;
p->next = r->next;
r->next = p;
r = p;
scanf("%d",&e);
}
return L;
}