-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_node.py
executable file
·112 lines (107 loc) · 2.63 KB
/
list_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from label import Label
class ListNode(object):
def __init__(self, ins, label = None, sys = False, opt = None):
self.ins = ins
self.next = None
self.prev = None
self.sys = sys
self.label = []
self.opt = opt
if label != None:
self.label.append(label)
def getNextInst(self):
current = self.next
while current != None and current.sys:
current = current.next
return current
def setNext(self, LN):
self.next = LN
LN.prev = self
return self
def setPrev(self, LN):
self.prev = LN
LN.next = self
return self
def appendLNs(self, LNs):
#print LNs
temp = self.next
current = self
for LN in LNs:
current.next = LN
LN.prev = current
current = LN
current.next = temp
temp.prev = current
return current
def append(self, *LNs):
temp = self.next
current = self
for LN in LNs:
current.next = LN
LN.prev = current
current = LN
current.next = temp
temp.prev = current
return current
def replaceLNs(self, LM, LNs):
temp = self.next
current = self.prev
"""
if(self.label!=None):
if(LNs[0].label==None):
LNs[0].label = self.label
else:
LNs[0].label = str(self.label) + ":" + str(LNs[0].label)
"""
#LNs[0].label = self.label
LNs[0].label += self.label
for LN in LNs:
current.next = LN
LN.prev = current
current = LN
current.next = temp
temp.prev = current
his = self.prev.next
del self
return his
def replace(self, LM, *LNs):
temp = self.next
current = self.prev
"""
if(self.label!=None):
if(LNs[0].label==None):
LNs[0].label = self.label
else:
LNs[0].label = str(self.label) + ":" + str(LNs[0].label)
"""
#LNs[0].label = self.label
LNs[0].label += self.label
for LN in LNs:
current.next = LN
LN.prev = current
current = LN
current.next = temp
temp.prev = current
his = self.prev.next
del self
return his
#def prepend(self, *LNs):
def remove(self):
self.prev.next = self.next
self.next.prev = self.prev
self.next.label += self.label
#print "test:"+str(self)+":::"+str(self.label)+"::::"+str(self.next.label)
del self
def label_string(self):
if len(self.label) == 0:
return None
return ":".join([str(x) for x in self.label])
def getALabel(self):
if len(self.label) != 0:
return self.label[0]
def addLabel(self, label):
self.label.append(label)
def labelStringArray(self):
return [x.name if type(x)==Label else x for x in self.label]
def __repr__(self):
return str(self.label_string()) + ":\t" + str(self.ins) if not self.sys else "// sys: "+str(self.ins)+"\t"+str(self.opt)