#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>
typedef struct node_type
{ int d;
struct node_type*next;
}node_type; //链点
typedef struct list_type
{ node_type*head;
node_type*tail;
int length;
}list_type;//链表
creat_list() //创建链表函数
{ node_type*new_node;
list_type list;
list.length=0;
list.head=NULL;
list.tail=NULL;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
while(new_node->d>=0)
{
if(list.length<=0)
{ new_node->next=NULL; //末尾指针初始化
list.head=new_node;
list.tail=new_node;
}
else
{ new_node->next=NULL; //末尾指针初始化
list.tail->next=new_node;
list.tail=list.tail->next;
}
list.length=list.length+1;
new_node=malloc(sizeof(struct node_type));
scanf("%d",&new_node->d);
}
return(list.head);
}
print_list(typedef struct node_type*head) //链表输出函数
{ node_type*p;
p=head;
while(p!=NULL)
{printf("%d ",p->d);
p=p->next;}
}
del_node(node_type*head) //删除链表中大于X的数据
{ int x;
node_type*last,*cur;
printf("请输入要删除的数据:");
scanf("%d",&x);
last=NULL;
cur=head;
while(cur!=NULL)
{ if(cur->d>x)
{ if(last==NULL)
{ head=cur->next;
cur=head;
}
else
{ last->next=cur->next;
cur=last->next;
}
}
else
{ last=cur;
cur=cur->next;
}
}
}
void main()
{ node_type*p;
p=creat_list();
del_node(p);
print_list(p);
}
30秒到达战场
相关分类