链表的实现
来源:互联网 发布:消逝的光芒修改数据 编辑:程序博客网 时间:2024/05/22 06:41
链表是一种非常重要的数据结构,比起数组来虽然操作繁琐,查找效率也不如数组效率高,但在进行插入删除操作时,链表具有数组无法比拟的效率,下面的代码是链表的实现
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 100
typedef struct node{
int item;
struct node * next;
}*link;
link NODE(int item, link next)
{
link p = malloc(sizeof *p);
p->item = item;
p->next = next;
return p;
}
void init_list(link head)
{
int i;
srand(time(NULL));
for(i = 0; i < N; i++)
head->next = NODE(rand()%100, head->next);
}
void delete(link head)
{
link p = head->next, front = head;
while(p != NULL)
{
if(p->item >= 30 && p->item <= 70)
{
front->next = p->next;
free(p);
p = front;
}
/* else
{
front = p;
p = p->next;
}
*/ front = p;
p = p->next;
}
}
void show_list(link head)
{
head = head->next;
while(head != NULL)
{
printf("%d ", head->item);
head = head->next;
}
printf("/n");
}
int main(void)
{
link head = NODE(-1, NULL);
init_list(head);
show_list(head);
printf("delete:/n");
delete(head);
show_list(head);
return 0;
}
- 链表的实现
- 链表的实现
- 链表的 实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- 链表的实现
- ORA-01031与存储过程和JOB
- error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
- linux 中 怎么更改启动linux画面
- 关于DB2的JDBC驱动
- 标准Linux文件系统层次标准(Filesystem Hierarchy Standard,FHS)第四章
- 链表的实现
- PowerShell2.0之桌面计算机维护(三)设置屏幕保护程序
- 标准Linux文件系统层次标准(Filesystem Hierarchy Standard,FHS)第五章
- Bresenham线算法
- linux下程序优化实践
- document.body.scrollTop值总为0的解决方法
- 123132
- Javascript获取页面元素的位置
- WCF 学习总结3 -- 实例模式