moveodinameselurndata:
1#-*-加密= utf-8-*-
2#软件:算法训练
3#datetime: 2020/4/8 11:13:
4:
5类节点(对象)。
6:
7 def __init __(独立地,data = None,next = none)。
8 self._value =数据
9个独立:_ next = next
10
11 def get_value(个体):
12个独立返回
13:
14 def get_next(个体):
15自行归还
16:
17 def set_value(独立地为new_data):
18 self._value = new_data:
19
20 def set_next(独立地为new_next)。
21 self._next = new_next:
22:
23:
24类LinkList(对象)。
25
26 def __init __(独立)。
27 self._head =节点()
28个独立:_tail = self._head
29本身:长度= 0
30
31 Def头(独立)。
32“”“
33链表的第一个元素(头节点除外)
34:归还
35“”“
36,如果独立的话:_head.get_next():
37自己返回:_head.get_next()
其他38人。
39返回节点()
40
41颤抖的尾巴(独立地)。
42“”“
43链表中的最后一项
44:归还
45“”“
46独立返回:_tail:
47:
48 def is_empty(独立)。
49“”“
50确定列表是否为空
51:归还
52“”“
53返回的自我身份._ length == 0
54:
大小55(个体经营)。
56“”“
57链表的大小
58归还
59“”“
60个独立退货
61:
62 def加(独立地,值)。
63“”“
64从头部插入环
65:参数值。
66:归还
67“”“
68 new_node =节点(值)
69 new_node.set_next(self._head.get_next())
70独立:_head.set_next(新节点)
71本人._ length + = 1
72:
73 def附件(独立,价值)。
74“”“
75从尾部增加结
76:参数值。
77:归还互联网价格图片大全
78“”“
79 new_node =节点(值)
80如果self.is_empty():
81 self._head.set_next(new_node)
其他82个。
83当前=自我
84到当前。Get_next():
85当前=当前。Get_next()
86 current.set_next(new_node)
87 self._tail =新节点:
88独立:_长度+ = 1
89
90 Def(搜索,值)。
91“”“
92查找数据,返回-1或节点索引
93.参数值。
94.回归。
95“”“
96当前=独立._ head.get_next()
97计数= 0
当前之前的98。Get_next():
如果当前为99,则Get_value()==值。
100收益计算
101当前=当前。Get_next()
102个帐户+ + 1
103返回-1
104:
105 Def删除(自动,值)。
106“”“
107删除下载返回此数据或-1
108:参数值。
109:归还
110“”“
111当前=自我
112首先=无
当前之前的113。Get_next():
114,如果当前.Get_value()==值。
115,如果没有提前。
116独立:_head = current。Get_next()
其他117人。
118 pre.set_next(current。Get_next())
119本身:_ length- = 1:
120返回当前值。
121第一=当前
122当前=当前。Get_next()
另一个123。
124返回-1
125
126:
安装127个默认值(独立,索引,值)。
128“”“
129插入数据节点
130:参数索引。
131:参数值。
132返回。
133“”“
134如果索引= 1:
135个(值)
136 Elif索引> self.size():
137个自我提升(价值)
138。
139 new_node =节点(值)
140次计算= 0
141当前=自我
142首=无
143并计数索引:
144计算+ = 1
145第一=当前
146 current = current.Get_next()
147 pre.set_next(new_node)
148 new_node.set_next(当前)
149 self__长度+ = 1
150:
151:
152 if __name__ ==‘__main__”。
153 arr = [1、4、2、6、8、4、9]
154年印刷(“质量长度”,Len(arr))
155 link_list =链接()
156打印(“空列表大小”,Link_list.size())
157打印(“列表是否为空?”,Link_list.is_empty())
158打印(“空列表中的第一个数据。”,Link_list.head()。Get_value())
159打印(“最新列表数据为空白。”,Link_list.tail()。Get_value())
160 for me arr。
161 link_list.append(i)
162:
163#添加:
164 link_list.append(10)
165 link_list.add(10)
166 link_list.insert(1、11)
167 link_list.insert(3,12)
168 link_list.insert(7,13)
169打印(“已删除的元素”,Link_list.remove(1))
170 link_list.append(1)
171 link_list.add(10)
172:
173当前= link_list.head()
174 l =“”
当前为175,Get_next():
176 l + =金钱(当前。Get_value())+“”
177 current = current.Get_next()
178 l + = money(current。Get_value())
179年印刷(“检查链表的值”,jb)
180次打印(“链接的尺寸列表”),Link_list.size())
181打印(“搜索链接列表。”,Link_list.search(8))
182打印(“链接列表中的第一个数据。”,Link_list.head()。Get_value())
183打印(“最近列出的数据”),Link_list.tail()。Get_value())
Python创建链接列表moveodinameselurndata
JS