AcWing 827. 双链表 题解

AcWing 827 双链表

个人记录自用,未加注释

/*
AcwWing 827. 双链表
2021年7月23日15:57:44
By ZenFish
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N = 1e5+10;

int main() {
	int e[N],idx = 2;
	pair<int,int> ne[N];
	ne[0] = {0,1},ne[1] = {0,1};	
	int M; cin >> M;
	while(M--) {
		string c; cin >> c;
		if(c == "L") {
			cin >> e[idx];
			ne[ne[0].second].first = idx;
			ne[idx].second = ne[0].second;
			ne[0].second = idx,ne[idx].first = 0;
			idx ++;
		} else if (c == "R") {
			cin >> e[idx];
			ne[idx].first = ne[1].first;
			ne[ne[1].first].second = idx;
			ne[1].first = idx,ne[idx].second = 1;
			idx ++;
		} else if(c == "D") {
			int k; cin >> k;
			ne[ne[k+1].first].second = ne[k+1].second;
			ne[ne[k+1].second].first = ne[k+1].first;
		} else if(c == "IL") {
			int k; cin >> k >> e[idx];
			ne[idx].first = ne[k+1].first;
			ne[ne[k+1].first].second = idx;
			ne[k+1].first = idx,ne[idx].second = k+1;
			idx ++;
		} else if(c == "IR") {
			int k; cin >> k >> e[idx];
			ne[ne[k+1].second].first = idx;
			ne[idx].second = ne[k+1].second;
			ne[k+1].second = idx,ne[idx].first = k+1;
			idx ++;
		}
	}
	for(int i = ne[0].second;i != 1;i = ne[i].second) {
		cout << e[i] << ' ';
	} cout << endl;
	//cout << ne[0].second;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值