#include <stdio.h>
#include <stdlib.h>
typedef struct _node{
int value;
struct _node *next;
int count;
}Node;
typedef struct _list{
Node * head;
Node * tail;
}List;
void print(List * temp)
{
int count=0;
Node * last=NULL;
for(last=temp->head;last;last=last->next,count++)
{
if(count%3==0)
printf("\n");
printf("序号:%d\t数值:%d\t",last->count,last->value);
}
printf("\n");
{
int number;
int count=0;
list->head=NULL;
list->tail=NULL;
do
{
printf("请填入值:");
scanf("%d",&number);
if(number != -1)
{
++count;
Node * temp=list->tail;
Node * p=(Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
p->count = count;
if(temp)
{
list->tail=p;
temp->next=list->tail;
}
else
{
list->head=p;
list->tail=list->head;
}
}
}while(number!=-1);
{
int found=0;
Node * last;
for(last=temp->head;last;last=last->next)
{
if(number==last->count)
{
printf("已找到\n序号为:%d\n数为:%d\n",last->count,last->value);
found=1;
}
}
}
void in_free(Node * temp)
{
temp->count=0;
temp->value=0;
temp->next=NULL;
temp=NULL;
free(temp);
}
void list_free(List * temp)
{
Node * last=(temp->head);
Node * p=NULL;
while(last)
{
p=last;
last=last->next;
in_free(p);
}
temp->head=NULL;
temp->tail=NULL;
}
int main()
{
int search;
int index;
List list;
scan(&list);
print(&list);
printf("请输入要查找的序号:");
scanf("%d",&index);
list_search(&list,index);
list_free(&list);
if(list.head==NULL)
printf("链表未找到");
else
printf("OK");
printf("末尾为:%s",list.head);
}
#include <stdlib.h>
typedef struct _node{
int value;
struct _node *next;
int count;
}Node;
typedef struct _list{
Node * head;
Node * tail;
}List;
void print(List * temp)
{
int count=0;
Node * last=NULL;
for(last=temp->head;last;last=last->next,count++)
{
if(count%3==0)
printf("\n");
printf("序号:%d\t数值:%d\t",last->count,last->value);
}
printf("\n");
}
{
int number;
int count=0;
list->head=NULL;
list->tail=NULL;
do
{
printf("请填入值:");
scanf("%d",&number);
if(number != -1)
{
++count;
Node * temp=list->tail;
Node * p=(Node*)malloc(sizeof(Node));
p->value = number;
p->next = NULL;
p->count = count;
if(temp)
{
list->tail=p;
temp->next=list->tail;
}
else
{
list->head=p;
list->tail=list->head;
}
}
}while(number!=-1);
}
{
int found=0;
Node * last;
for(last=temp->head;last;last=last->next)
{
if(number==last->count)
{
printf("已找到\n序号为:%d\n数为:%d\n",last->count,last->value);
found=1;
}
}
}
void in_free(Node * temp)
{
temp->count=0;
temp->value=0;
temp->next=NULL;
temp=NULL;
free(temp);
}
void list_free(List * temp)
{
Node * last=(temp->head);
Node * p=NULL;
while(last)
{
p=last;
last=last->next;
in_free(p);
}
temp->head=NULL;
temp->tail=NULL;
}
int main()
{
int search;
int index;
List list;
scan(&list);
print(&list);
printf("请输入要查找的序号:");
scanf("%d",&index);
list_search(&list,index);
list_free(&list);
if(list.head==NULL)
printf("链表未找到");
else
printf("OK");
printf("末尾为:%s",list.head);
}