当前位置:网站首页>7-11 重排链表 (25 分)
7-11 重排链表 (25 分)
2022-04-23 03:03:00 【学习kl&tk】
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5+5;
vector<int>ans;
deque<int>d;
int head,n,x;
struct node{
int l,val,r;
}arr[N];
int main()
{
cin >> head >> n;
for(int i=0 ;i<n;i++){
cin >> x;
cin >> arr[x].val >> arr[x].r;
arr[x].l = x;
}
while (head!=-1){
d.push_back(arr[head].l);
head=arr[head].r;
}
while (!d.empty()){
ans.push_back(d.back());
d.pop_back();
if(d.empty()) break;
ans.push_back(d.front());
d.pop_front();
}
int len = ans.size();
for(int i=0;i<len ; i++){
if(i == len-1) printf("%05d %d -1\n",ans[i],arr[ans[i]].val);
else printf("%05d %d %05d\n",ans[i],arr[ans[i]].val,ans[i+1]);
}
return 0;
}
版权声明
本文为[学习kl&tk]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_53013914/article/details/124326124
边栏推荐
- 《信息系统项目管理师总结》第七章 项目沟通管理
- ASP.NET 6 中间件系列 - 自定义中间件类
- TP5 where query one field is not equal to multiple values
- Reverse a linked list < difficulty coefficient >
- MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
- Kubernetes - Introduction to actual combat
- Encapsulate components such as pull-down menu based on ele
- Winsock programming interface experiment: Ping
- Opencv combines multiple pictures into video
- How to deploy a website with only a server and no domain name?
猜你喜欢
Response processing of openfeign
Opencv fills the rectangle with a transparent color
AC & A2C & A3C
最通俗易懂的依赖注入之服务容器与作用域
TP5 email (2020-05-27)
C# WPF UI框架MahApps切换主题
Shell script learning notes - regular expressions
Introduction to ACM [inclusion exclusion theorem]
MYSQL03_ SQL overview, rules and specifications, basic select statements, display table structure
Judge whether there is a leap year in the given year
随机推荐
HLS / chisel practice CORDIC high performance computing complex square root
Source Generator实战
Numpy append function
MYSQL_ From mastery to abandonment
【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
Openfeign timeout setting
如果通过 C# 实现对象的深复制 ?
Introduction to ACM [inclusion exclusion theorem]
Systemctl start Prometheus + grafana environment
Shell script learning -- practical case
C# 11 对 ref 和 struct 的改进
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
Binary tree
eventBus
Array and collection types passed by openfeign parameters
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
ASP.NET 6 中间件系列 - 执行顺序
Use of MySQL command line client and common commands
REINFORCE
Numpy stack function