关于函数形参调用问题!
以下是定位链表中某元素的位置的程序:
#include <stdio.h>
#include <malloc.h>
typedef char ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LinkList CreateLinkList(void)
{
char ch;
LinkList head;
LNode *p;
head = NULL;
ch = getchar();
while(ch !='\n')
{
p = (LNode*)malloc(sizeof(LNode));
p->data = ch;
p->next = head;
head = p;
ch = getchar();
}
return (head);
}
int LocateElem(LinkList L, ElemType x)
{
int i = 0;
LinkList p;
p = L;
while(p && p->data != x)
{
i++;
p = p->next;
}
if(!p)
return 0;
else
return i;
}
main()
{
LinkList list;
int Loc;
char x;
list = CreateLinkList();
printf("请输入需要查找的元素:");
x = getchar();
Loc = LocateElem(list,x);
printf("该元素在链表中第一次出现的位置为:%d\n",Loc);
}