AcWing 827. 双链表python3
原题链接
简单
作者:
xanxus1111
,
2020-04-28 14:39:06
,
所有人可见
,
阅读 564
e,l,r,idx = [0]*100010,[-1]*100010,[-1]*100010,2
r[0], l[1] = 1, 0
def delete(k):
r[l[k]] = r[k]
l[r[k]] = l[k]
def add(k,x):
global idx
e[idx] = x
r[idx] = r[k]
l[idx] = k
l[r[k]] = idx
r[k] = idx
idx += 1
def operate(s):
if s[0] == 'I':
k,x = map(int,s[2:].split())
if s[1] == 'L':
add(l[k+1],x)
elif s[1] == 'R':
add(k+1,x)
elif s[0] == 'L':
x = int(s[1:])
add(0,x)
elif s[0] == 'R':
x = int(s[1:])
add(l[1],x)
elif s[0] == 'D':
k = int(s[1:])
delete(k+1)
if __name__ == "__main__":
n = int(input())
for i in range(n):
s = input()
operate(s)
i = r[0]
while i != 1 :
print(e[i],end=' ')
i = r[i]