蓝桥杯备考:单向链表模板题

蓝桥杯备考:单向链表模板题_第1张图片

#include 
using namespace std;
const int N = 1e6+10;
int ne[N],e[N],id;
int mp[N];
int main()
{
	id++;
	e[id] = 1;
	ne[id] = 0;
	mp[e[id]] = id;
	int q;cin >> q;
	while(q--)
	{
		int op,x;cin >> op >> x;
		int pos = mp[x];
		if(op == 1)
		{
			int y;cin >> y;
			id++;
			e[id] = y;
			ne[id] = ne[pos];
			ne[pos] = id;
			mp[y] = id;
		}
		else if(op == 2)
		{
			cout << e[ne[pos]] << endl;
		}
		else
		{
			ne[pos] = ne[ne[pos]];
		}
	}	
	
	
	
	return 0;
}

你可能感兴趣的:(链表,数据结构)