#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct Node
{
int data;
struct Node *next;
}List;
void InputList(List *);
int Inserta(List *,int);
main()
{
int d;
List *h;
h=(List *)malloc(sizeof(List));
InputList(h);
while(1)
{
printf("请输入要查找的点:\n");
scanf("%d",&d);
Inserta(h,d);
}
return 0;
}
void InputList(List *H)
{
int i,n,a;
List *p,*q;
p=H;
printf("请输入结点数量:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
q=(List *)malloc(sizeof(List));
printf("请为第%d个结点赋值:\n",i+1);
scanf("%d",&a);
q->data=a;
q->next=NULL;
p->next=q;
p=q;
}
}
int Inserta(List *H,int d)
{
List *p,*q;
p=H->next;
while(p->next!=NULL)
{
if(p->data==d)
{
printf("存在\n");
return 0;
}
else
p=p->next;
}
if(p->data==d)
{
printf("存在\n");
}
else
{
printf("不存在,尾部加入该新结点\n");
q=(List *)malloc(sizeof(List));
q->data=d;
q->next=NULL;
p->next=q;
}
return 0;
}