Skip to content

Commit

Permalink
Create 02-线性结构3 Reversing Linked List (25 分).cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hao14293 authored May 1, 2019
1 parent 5b5890c commit 0268804
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
int first, n, k, temp;
cin >> first >> n >> k;
int data[100000], next[100000], list[100000];
for(int i = 0; i < n; i++){
cin >> temp;
cin >> data[temp] >> next[temp];
}
int sum = 0;
while(first != -1){
list[sum++] = first;
first = next[first];
}
for(int i = 0; i < (sum - sum % k); i += k)
reverse(begin(list) + i, begin(list) + i + k);
for(int i = 0; i < sum - 1; i++)
printf("%05d %d %05d\n", list[i], data[list[i]], list[i + 1]);
printf("%05d %d -1", list[sum - 1], data[list[sum - 1]]);
return 0;
}

0 comments on commit 0268804

Please sign in to comment.