数据结构---链表
来源:互联网 发布:flyme系统依赖网络 编辑:程序博客网 时间:2024/06/09 14:00
typedef struct node{int data;struct node *next;}*Linklist,Lnode;
尾插法建链表:
Linklist creat_list_tail(){Linklist Head;Head=(Linklist)malloc(sizeof(Lnode));Head->next=NULL;Lnode *r,*p;r=Head;int x;scanf("%d",&x);while(x!=-1){p=(Linklist)malloc(sizeof(Lnode));p->data=x;p->next=r->next;r->next=p;r=p;scanf("%d",&x);}return Head;}
头插法建链表:
Linklist creat_list_head(){Linklist Head;Lnode *p;Head=(Linklist)malloc(sizeof(Lnode));Head->next=NULL;int x;scanf("%d",&x);while(x!=-1){p=(Linklist)malloc(sizeof(Lnode));p->data=x;p->next=Head->next;Head->next=p;scanf("%d",&x);}return Head;}
删除链表重复值:void pur_list(Linklist Head){Lnode *p,*q,*r;p=Head->next;if(p!=NULL)while(p){q=p;while(q->next){if(q->next->data==p->data){r=q->next;;q->next=r->next;free(r);}elseq=q->next;}p=p->next;}}
链表插入排序:void insert_operation(Linklist head,Lnode *temp){Lnode *prev,*cur;//第一个数据前插入 tempif(temp->data< head->data){temp->next=head;//此处的head是第一个数据 head=temp;return ; } cur=head; while(cur) { if(temp->data < cur->data) break;//找到插入位置,大于prev 小于prev->next 插入到prev之后,prev->next之前 prev=cur; cur=cur->next; } temp->next=prev->next;// 插入到prev之后,prev->next之前 prev->next=temp; return ;}void sort_list(Linklist Head)//插入法排序 {Lnode *prev,*curr,*head;head=Head->next;if(Head==NULL)return ;curr=head->next;head->next=NULL;while(curr){prev=curr;curr=curr->next;insert_operation(head,prev);//寻找prev的插入位置 }return ;}
链表倒置:
void Reverse(Linklist Head)//链表的倒置 {Lnode *p,*q;p=Head->next;Head->next=NULL;while(p){q=p;p=p->next;q->next=Head->next;Head->next=q;}}
0 0
- 数据结构---链表
- 数据结构 - 链表
- 【数据结构】链表
- 数据结构-链表
- '数据结构' 链表
- 数据结构-链表
- 【数据结构】链表
- 数据结构--链表
- 【数据结构】 链表
- 数据结构--链表
- 数据结构-链表
- 数据结构 - 链表
- 链表 - 数据结构
- 数据结构:链表
- [数据结构]链表
- 数据结构--链表
- 【数据结构】链表
- 数据结构-链表
- 唯一分解定理
- 算法训练 全排列 JAVA
- ORA-02437 使对已有数据不检查的主键约束生效
- LINUX 使用tcgetattr与tcsetattr函数控制终端
- CSS3时光轴 -时间线 特效-来自 www.srcfans.com
- 数据结构---链表
- 【复杂网络学习笔记】3:完整的小世界网络
- x-requested-with请求头与Ajax
- java知识平时积累
- 堆栈的例子——来解决计算机的表达式计算
- 功率谱密度
- effective STL 读书笔记——第四章:迭代器
- EOJ 3260袋鼠妈妈找孩子 (DFS)
- Financial Management