1052 (未完成)
来源:互联网 发布:取名软件免费版 编辑:程序博客网 时间:2024/06/05 12:01
1052. Linked List Sorting (25)
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the structures according to their key values in increasing order.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive N (< 105) and an address of the head node, where N is the total number of nodes in memory and the address of a node is a 5-digit positive integer. NULL is represented by -1.
Then N lines follow, each describes a node in the format:
Address Key Next
where Address is the address of the node in memory, Key is an integer in [-105, 105], and Next is the address of the next node. It is guaranteed that all the keys are distinct and there is no cycle in the linked list starting from the head node.
Output Specification:
For each test case, the output format is the same as that of the input, where N is the total number of nodes in the list and all the nodes must be sorted order.
Sample Input:5 0000111111 100 -100001 0 2222233333 100000 1111112345 -1 3333322222 1000 12345Sample Output:
5 1234512345 -1 0000100001 0 1111111111 100 2222222222 1000 3333333333 100000 -1
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;struct NODE{int adr;int key;int next;}node[100001];bool cmp(NODE a,NODE b){return a.key<=b.key;}int main(){int i,n,first,ad;scanf("%d %d",&n,&first);int key,next;for(i=0;i<n;i++){scanf("%d%d%d",&ad,&key,&next);node[i].adr=ad;node[i].key=key;node[i].next=next;}sort(node,node+n,cmp);for(i=0;i<n-1;i++){node[i].next=node[i+1].adr;}printf("%d %d\n",n,node[0].adr);for(i=0;i<n-1;i++)printf("%05d %d %05d\n",node[i].adr,node[i].key,node[i].next);printf("%05d %d %d\n",node[i].adr,node[i].key,-1);return 0;}\\只过了两个测试点,待勘误\\
- 1052 (未完成)
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- 未完成
- wifi 未完成
- 单链表未完成
- ioctl (未完成)
- 未完成代码
- iOS推送实现/ 服务器向iOS APP推送消息
- Leetcode-133. Clone Graph
- Android之二维码生成与扫描
- MYSQL基础1
- iOS UITableViewCell点击效果,点击后消失
- 1052 (未完成)
- PHP 亚洲常用时区编码
- ARPSpoofing、arp欺骗性攻击、arpspoof源码分析
- Auto install opencv after installing Ubuntu
- Android 数据库框架ormlite 使用精要
- ASP.Net刷新页面后自动滚动到原来位置方法汇总
- windows下忘记MySQL密码的修改方法
- leetcode
- 浅谈单例模式