一个关于用c语言实现链表查找的问题,急~~~(30分)

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:10:34
请问如何在下列程序中插入“链表的查找”这部分程序?(要能够在Turbo C中运行成功的)

#include<stdio.h>
#include<stdlib.h>
#define NULL0
#define LEN sizeof(struct student)
struct student
{long num;
struct student *next;
};
int n;
struct student *creat(void)
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student*)malloc(LEN);
scanf("%ld",&p1->num);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld",&p1->num);
}
p2->next=NULL;

return(head);
}
void print(struct student *head)
{struct student *p;
printf("\nThese %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%ld\n",p->num);
p=p->next;
}while(p!=NULL);
}

struct student *FinByVal(struct student *TH_Fin,long val_Fin)
{//查找num域不大于指定值的节点,除非头节点的num域就大于指定值
struct student *i
if(TH_Fin==NULL)
i=NULL;
else
for(i=TH_Fin;i->Next!=NULL&&i->num!=val_Fin&&i->Next->num<=val_Fin;i=i->Next);
return(i);
}