数据结构实验之链表六:有序链表的建立
来源:互联网 发布:中国产能利用率数据 编辑:程序博客网 时间:2024/06/10 15:06
数据结构实验之链表六:有序链表的建立
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入N个无序的整数,建立一个有序链表,链表中的结点按照数值非降序排列,输出该有序链表。
输入
第一行输入整数个数N;
第二行输入N个无序的整数。
第二行输入N个无序的整数。
输出
依次输出有序链表的结点值。
示例输入
633 6 22 9 44 5
示例输出
5 6 9 22 33 44
提示
不得使用数组!
来源
#include<bits/stdc++.h>using namespace std;typedef struct node{ int data; struct node *next;}LNode,*LinkList;LinkList CreatList(int n){ LNode *head,*p1,*p2,*p3; head=new LNode; head->next=NULL; for(int i=0;i<n;i++) { p1=new LNode; cin>>p1->data; p1->next=NULL; p2=head; p3=head->next; while(p3!=NULL&&p1->data>p3->data) { p3=p3->next; p2=p2->next; } p1->next=p3; p2->next=p1; } return head;}void DisplayList(LinkList head){ LNode *p; p=head->next; while(p!=NULL) { p->next==NULL?cout<<p->data<<endl:cout<<p->data<<" "; p=p->next; }}int main (){ int n,i; cin>>n; LNode *head; head=CreatList(n); DisplayList(head); return 0;}
0 0
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- SDUToj2121数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- SDUT2121数据结构实验之链表六:有序链表的建立
- 数据结构实验之链表六:有序链表的建立
- 在csdn里面的第一篇博客
- 项目技术总结一之JSONP实现跨域调度
- 学习笔记------数据结构(C语言版)串的定长顺序存储表示
- bzoj1692 队列变换
- ORA-09817错误
- 数据结构实验之链表六:有序链表的建立
- 【SoapUI】在soapui中使用Groovy脚本常用方法
- HTML5开发实战——Sencha Touch篇(2)
- 学习笔记
- 关于博客的头像问题
- 从windows客户端sqlplus连接Oracle 12c PDB报错ORA-65162: The password has expired
- BlogApp之spring整合Guava中的AsyEventBus异步事件
- Machine Learning - An Introduction
- hdu3341Lost's revenge (AC自动机+变进制dp)