双链表操作 written by my self
来源:互联网 发布:快速优化软件 编辑:程序博客网 时间:2024/04/29 17:15
struct student
{
int data;
struct student *next;
struct student *pre;
}dnode;
1, 删除节点
dnode *del(dnode *head, int num)
{
dnode *p1;
p1=head;
while(p1->data!=num&&p1->next!=NULL)
{p1=p1->next;}
if(num == p1->data)
{
if(p1==head)
{
head = head->next;
head->pre=NULL
free(p1);
}
else if(p1->next==NULL)
{
p1->pre->next=NULL;
free(p1);
}
else
{
p1->next->pre=p1->pre;
p1->pre->next = p1->next;
free(p1);
}
}
else
printf("%d is not found",num);
return head;
}
2, 插入节点
dnode *insert(dnode *head, int num)
{
dnode *p1, *p0;
p1=head;
p0=(dnode *)malloc(sizeof(dnode));
p0->data=num;
while(p0->data>p1->data&&p1->next!=NULL)
{
p1=p1->next;
}
if(p0->data<=p1->data)
{
if(head == p1)
{
p0->next = p1;
p1->pre = p0;
head = p0;
}
else
{
p1->pre->next = p0;
p0->next = p1;
p0->pre = p1->pre;
p1->pre = p0;
}
}
else
{
p1->next = p0;
p0->pre = p1;
p0->next = NULL;
}
return head;
}
- 双链表操作 written by my self
- 单链表操作 written by myself
- SpringMVC messageTool written by self for velocity I18N
- my self
- Papers written by Googlers
- Improve my written English skill
- My first written in Blog
- suffix array written by myself
- Quantify written by Keith Braithwaite
- lua by written form c
- My self-introduction
- My first program written in Python
- PyRename: 批量重命名工具, written by Python
- Preferrence usage(written by 猪头小队长)
- Rebuild my self with .net!
- stand by my side
- My BTree by C++
- my self for beihang authenticate url
- sleep()与wait()的区别
- C++相关
- 50个c/c++源代码网站
- 如果爱...
- 学习札记之《计算机达人成长之路》
- 双链表操作 written by my self
- 第十三堂课后作业
- 点击表格行时,实现复选框或者单选按钮反选
- 拖动改变表格宽度
- AndroidManifest.xml解析(三)
- 新浪微博/腾讯微博登录openstack horizon
- 教你如何破解 Sencha Architect 2 (ExtJs Designer)
- poj 1681 Painter's Problem 高斯消元
- 犀牛书第4章 变量(下篇):深入理解JavaScript中的变量作用域