众所周知,链表是数据结构的基础,掌握链表很重要!
#include <stdio.h>
#include <stdlib.h>
typedef struct NODE
{
int e;
struct NODE *next;
}node, *LinkList;
LinkList build_linklist()
{
FILE *fp;
if ((fp=fopen("number.txt","r"))==NULL)
{
printf("Can not open the file!");
exit (1);
}
int t;
LinkList r,p,head=NULL;
while (fscanf(fp,"%d",&t)>0)
{
p=(LinkList)malloc(sizeof(node));
p->e=t;
p->next=NULL;
if (!head)
head=p;
else
r->next=p;
r=p;
}
return head;
}
void search(LinkList head,int toSearch)
{
int count=0;
int flag=0;
LinkList r=head;
while (r!=NULL)
{
count++;
if (r->e==toSearch)
{
printf(&#