【数据结构】单向有序链表---最水的代码
来源:互联网 发布:闲鱼.淘宝二手 编辑:程序博客网 时间:2024/06/05 04:55
上代码,自己模拟
#include<iostream>using namespace std;struct node{int data;node *next;} ;void search(node *,node *);void insert(node *,node *);void insert(node *,node *,node *);void print(node *);int main(){node *head,*p,*s;s=new node;head=new node;head->next=s;cin>>s->data;p=s;s->next=NULL;while(s->data!=0){s=new node;cin>>s->data;search(head,s);}print(head);}void search(node *head,node *s){node *p;bool swi;swi=false;for(p=head->next;p->next!=NULL;p=p->next){if(s->data>=p->data&&s->data<p->next->data){insert(p,p->next,s);swi=1;goto abc;}}if(swi==false)insert(p,s);abc: ;}void insert(node *p,node *s){p->next=s;s->next=NULL;}void insert(node *p,node *q,node *s){s->next=q;p->next=s;}void print(node *head){node *p;for(p=head->next;p->next!=NULL;p=p->next)cout<<" "<<p->data;}
写程序的时候纠结了一个小时,不出结果,还以为链表建错了,最后发现没输出,汗!!!!
- 【数据结构】单向有序链表---最水的代码
- 数据结构之链表面试题汇总(二)-有序单向链表的合并、单向链表反转
- 有序单向链表的相关操作
- 两个有序单向链表的合并
- 将两个有序的单向链表整合成一个有序单向链表
- 单向循环链表的有序插入 对单向循环链表head插入元素 链表保持有序
- 数据结构-单向链表
- 【数据结构】单向链表
- [数据结构] 单向链表
- 数据结构~~单向链表
- 数据结构单向链表
- 数据结构-单向链表
- 数据结构 单向链表
- 数据结构--单向链表
- 数据结构练习--单向链表的实现
- 数据结构单向链表的理解
- 数据结构:单向链表的逆序
- 最简洁的单向链表逆序
- RoR利用Google邮件服务器的方法
- Hadoop MapReduce进阶 使用Chain
- const成员函数和mutable关键字
- 在MSSQL里把字串转成table变量
- HDOJ 2206:IP的计算 这道题的边界条件可以挑战你的想象力
- 【数据结构】单向有序链表---最水的代码
- 对自定义类实现排序的四种方法
- MS sqlserver2000 master库语言排序规则不一致导致的问题
- WAR and EAR file format
- VC6的快捷键
- B树、B-树、B+树、B*树
- Oracle merge
- code::blocks gcc wxwidgets wxsmith纠结的汉字
- 子窗口关闭时刷新父窗口