双链表的基本操作
来源:互联网 发布:淘宝上开店怎么找货源 编辑:程序博客网 时间:2024/05/21 17:22
#include <iostream>#include <stdio.h>#include <string.h>#include <cnio.h>using namespace std;typedef struct student{int data;struct student *next;struct student *pre;}dnode;//建立双链表dnode *create(){dnode *head,*p,*s;int x,cycle = 1;head = (dnode*)malloc(sizeof(dnode));p = head;while(cycle){printf("\nplease input the data:);scanf("%d",&x);if(x!=0){s = (dnode*)malloc(sizeof(dnode));s->data = x;printf("\n%d",s->data);p->next = s;s->pre = p;p =s;}elsecycle = 0;}head = head->next;head->pre = NULL;p->next = NULL;printf("\n %d ",head->data);return head;}
//双链表删除节点dnode *del(dnode *head,int num){dnode *p1,*p2;p1 = head;while(num!=p1->data && 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;}}elseprintf("\n%d could not been found",num);return head;}
//双链表插入节点dnode *insert(dnode *head,int num){dnode *p0,*p1;p1 = head;p0 = (dnode*)malloc(sizeof(dnode));p0->datas = num;while(p0->data>p1->data && p1->next!= NULL){p1 = p1->next;}if(p0->data<=p1->data){if(head==p1){p0->next = p1;p1->next = p0;head = p0;}else{p1->pre->next = p0;p0->next = p1;p0->pre = p1->pre;p1->next = p0;}}else{//比哪个都大的情况p1->next = p0;p0->next = p1;p0->next =NULL;}return head;}
0 0
- 双链表的基本操作
- 双链表的基本操作
- 双链表的基本操作
- 双链表的基本操作
- C++ 双链表的基本操作
- 单链表、双链表的基本操作
- 双链表的基本操作实现
- 数据结构之双链表的基本操作
- 循环双链表的基本操作实现
- 循环双链表的基本操作实现
- 双链表的增删改查基本操作
- SQL的基本操作
- 树的基本操作
- SQL的基本操作
- 单链表的基本操作
- XML的基本操作!
- db2的基本操作
- linux的基本操作
- poj 1015 动态规划 难
- 基于Linux的USB子系统学习 --- <基础知识与USB协议概述> ing
- dos命令总结大全
- 黑马程序员——Java集合框架—Set
- txt 转换为 html 解析文本 自动打上标签
- 双链表的基本操作
- 谬论之程序员的眼光看世界
- Java-Map集合
- HDU 1114 (dp 完全背包)
- poj 1273Drainage Ditches(简单网络流(用dinic))
- throw er; // Unhandled 'error' event
- 云计算平台管理的三大利器Nagios、Ganglia和Splunk
- Fiddler 教程
- zoj 3747