链表的重要总结 系列二
来源:互联网 发布:软件验收甲方发言稿 编辑:程序博客网 时间:2024/06/06 09:46
输出 链表的函数。
void input(struct node *head)
{
struct node *tail;
for(tail = head -> next; tail != NULL; tail = tail -> next)
{
printf("%d", tail -> data);
if(tail -> next != NULL)
printf(" ");
else printf("\n");
}
}
{
struct node *tail;
for(tail = head -> next; tail != NULL; tail = tail -> next)
{
printf("%d", tail -> data);
if(tail -> next != NULL)
printf(" ");
else printf("\n");
}
}
对于含有头结点的 n个结点的链表, 删除相同数据的结点,记录剩下结点的数量并返回的函数。
int del(struct node *head, int n)
{
struct node *p, *tail, *t;
for(p = head -> next; p -> next != NULL; p = p -> next)
{
tail = p;
t = tail -> next;
while(t -> next != NULL)
{
if(p -> data == t -> data)
{
tail -> next = t -> next;
free(t);
n--;
t = tail -> next;
}
else
{
tail = t;
t = t -> next;
}
}
if(t -> next == NULL)
{
if(t -> data == p -> data)
{
tail -> next = NULL;
free(t);
n--;
}
}
}
return n;
}
{
struct node *p, *tail, *t;
for(p = head -> next; p -> next != NULL; p = p -> next)
{
tail = p;
t = tail -> next;
while(t -> next != NULL)
{
if(p -> data == t -> data)
{
tail -> next = t -> next;
free(t);
n--;
t = tail -> next;
}
else
{
tail = t;
t = t -> next;
}
}
if(t -> next == NULL)
{
if(t -> data == p -> data)
{
tail -> next = NULL;
free(t);
n--;
}
}
}
return n;
}
2 0
- 链表的重要总结 系列二
- 链表的重要总结 系列一
- 链表的重要总结 系列三
- 链表的重要总结 系列四
- Timesten系列之二:timesten重要的连接属性(参数)
- linux中断系列之中断重要的数据结构(二)
- 重要的属性二
- 重要的函数总结。
- 编程中常用的重要的数据结构实现(二)之链表
- 数据结构的重要概念总结
- Service重要的知识点总结
- Storm系列(二)系统结构及重要概念
- Apache 2.0系列的重要安全补丁 >
- Mysql重要不常用的函数系列
- 深入理解容器系列之二--------ArrayList的总结
- 英语总结系列(二十四):历经GCT的一月
- Maven学习总结系列二:Maven的安装和配置
- Kafka总结系列(二)
- lua和python利用协程实现消费-生产者问题
- Android自带的emoji表情的使用
- shiro 实现单用户登录,一个用户同一时刻只能在一个地方登录
- FJNU第二十届低年级程序设计竞赛(正式赛)-Problem F-火柴棒
- C++中整型随机数发生器的写法
- 链表的重要总结 系列二
- 大话ArrayList
- IIC常遇问题
- java单例设计模式中你可能不知道的秘密
- A. Greg's Workout
- <C++>_C++的枚举
- fastdfs相关状态和信息查看
- 深入理解HashMap
- POJ 2387 Til the Cows Come Home dijkstraA