# 可以使用简单的列表来做这个链表,但是失去了本身的链表的意思
class Node:
def __init__(self,val):
self.val = val
self.next = None
class Listlink:
def __init__(self):
self.head = None
def insert(self, x, y):
node = Node(y)
if self.head == None:
node = Node(y)
self.head = node
return
if self.head.val == x:
node.next = self.head
self.head = node
return
pre = self.head
cur = self.head.next
while cur:
if cur.val == x:
pre.next = node
node.next = cur
return
pre = cur
cur = cur.next
pre.next = node
def delete(self,x):
if self.head == None:
return
pre = self.head
cur = pre.next
if self.head.val == x:
self.head = cur
return
while cur:
if cur.val == x:
if cur.next == None:
pre.next = None
return
pre.next = cur.next
return
pre = cur
cur = cur.next
def display(self):
cur = self.head
if cur == None:
print("NULL")
return
while cur:
print(cur.val,end = " ")
cur = cur.next
if __name__ == "__main__":
link = Listlink()
n = int(input())
for item in range(n):
s = list(input().split())
if s[0] == "insert":
link.insert(int(s[1]),int(s[2]))
elif s[0] == "delete":
link.delete(int(s[1]))
link.display()