//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
const int N=1e5+10;
//定義
int e[N],pre[N],ne[N],h,id;
int mp[N];
//頭插
// ?兵 ? ? ? ? ?y
// ? ? ? ?x?
void push_front (int x)
{
id++;
e[id]=x;
mp[x]=id;
pre[id]=h;
ne[id]=ne[h];
//先修改新節點?
//?? ? pre[ne[id]]=id; ? ?ne【id】就是ne【h】看上邊,剛賦的值?
pre[ne[h]]=id;
//?? ? pre[id]=h;
ne[h]=id; //最后改這個?
}?
// 遍歷打印,無視pre即可
void print()
{
for(int i=ne[h];i;i=ne[i])
{
cout<<e[i]<<" ";
}cout<<endl;
}?
// 按值查找,mp數組優化·
int find(int x)
{
return (mp[x]);
}?
// 任意位置(存儲位置,下標)之后插入
// ? p
// ? 1 ? ? ? 3
// ? ? ? x ?
void insert(int p,int x)
{
id++;
e[id]=x;
mp[x]=id;
pre[id]=p;
ne[id]=ne[p];
//?? ?pre[id]=p;
pre[ne[p]]=id;
ne[p]=id;
}?
//任意位置(存儲位置,下標)之前插入
// ? ? ? ? ? ? ? ?p
// ? ? ?1 ? ? ? ? 2
// ? ? ? ? ? x?
void insret_front(int p,int x)
{
id++;
e[id]=x;
mp[x]=id;
ne[id]=p;
pre[id]=pre[p];
ne[pre[p]]=id;
pre[p]=id;
}
//刪除任意位置元素
// ? ? ? ? p
// ? 1 ? ? ? ? ?2
//?? ? ? ? ? x?
void erase(int p)
{
//?? ?mp[p]=0; 這個不對?
mp[e[p]]=0;
ne[pre[p]]=ne[p];
pre[ne[p]]=pre[p];
}?
int main()
{
for(int i=0;i<6;i++)
{
push_front(i);
}
print();
cout<<?? ?find(0)<<endl;
cout<<?? ?find(2)<<endl;
insert(1,33);
print();
insert(7,88);
print();
cout<<?? ?find(33)<<endl;
cout<<?? ?find(88)<<endl;
insret_front(1,66);
print();
insret_front(3,33);
print();
insret_front(8,100);
print();
insret_front(9,666);
print();?
erase(1);
print();?
cout<<?? ?find(100)<<endl;
erase(11);
print();?
erase(7);
print();?
erase(find(666));
print();?
return 0;
}?