pat 1074 Reversing Linked List
Posted huayra
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pat 1074 Reversing Linked List相关的知识,希望对你有一定的参考价值。
1 #include<iostream> 2 #include<vector> 3 #pragma warning(disable:4996) 4 5 using namespace std; 6 7 struct Node 8 { 9 int data; 10 int next; 11 }; 12 13 int main() 14 { 15 int first, address, n, k, cnt = 1, L = 100000; 16 Node List[100005]; //使用静态链表 17 cin >> first >> n >> k; 18 while (n) //读取数据 19 { 20 --n; 21 cin >> address; 22 cin >> List[address].data >> List[address].next; 23 } 24 List[L].next = -1; 25 int b = first, e = first, r = L; 26 while (e != -1) 27 { 28 if (cnt % k != 0) 29 { 30 e = List[e].next; 31 ++cnt; 32 } 33 else 34 { 35 int t = List[e].next; 36 int p; 37 for (p = b; p != e;) 38 { 39 int q = List[p].next; 40 List[p].next = List[r].next; 41 List[r].next = p; 42 p = q; 43 } 44 List[p].next = List[r].next; 45 List[r].next = p; 46 r = b; 47 e = t; 48 b = e; 49 ++cnt; 50 } 51 } 52 List[r].next = b; 53 int p; 54 for (p = List[L].next; List[p].next != -1; p = List[p].next) 55 printf("%05d %d %05d ", p, List[p].data, List[p].next); 56 printf("%05d %d %d", p, List[p].data, List[p].next); 57 58 system("pause"); 59 return 0; 60 }
使用静态链表
以上是关于pat 1074 Reversing Linked List的主要内容,如果未能解决你的问题,请参考以下文章
PAT (Advanced Level) 1074. Reversing Linked List (25)
PAT甲级1074 Reversing Linked List (25 分)
1074 Reversing Linked List (25 分)
1074 Reversing Linked List (25)