# include<iostream>
using namespace std;
int a[100005];
int b[100005];
int data1[100005];
int main(void)
{
int p0, num, x;
scanf("%d %d %d", &p0, &num, &x);
for (int i = 0; i < num; i++)
{
int node, data0, next;
scanf("%d %d %d", &node, &data0, &next);
data1[node] = data0;
a[node] = next;
}
int cnt = 0;
while (p0 != -1)
{
b[cnt++] = p0;
p0 = a[p0];
}
for (int i = 0; i < cnt - (cnt % x); i += x)
{
for (int j = 0; j < x / 2; j++)
{
int tomb;
tomb = b[i + j];
b[i + j] = b[i + x - j - 1];
b[i + x - j - 1] = tomb;
}
}
for (int i = 0; i < cnt - 1; i++)
{
printf("%05d %d %05d\n", b[i], data1[b[i]], b[i + 1]);
}
printf("%05d %d -1\n", b[cnt - 1], data1[b[cnt - 1]]);
return 0;
}
02-线性结构3 Reversing Linked List (25 分)
最新推荐文章于 2024-09-10 00:01:10 发布