色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

python如何對鏈表操作

瀏覽:6日期:2022-07-08 17:29:26

鏈表

鏈表(linked list)是由一組被稱為結點的數據元素組成的數據結構,每個結點都包含結點本身的信息和指向下一個結點的地址。由于每個結點都包含了可以鏈接起來的地址信息,所以用一個變量就能夠訪問整個結點序列。也就是說,結點包含兩部分信息:一部分用于存儲數據元素的值,稱為信息域;另一部分用于存儲下一個數據元素地址的指針,稱為指針域。鏈表中的第一個結點的地址存儲在一個單獨的結點中,稱為頭結點或首結點。鏈表中的最后一個結點沒有后繼元素,其指針域為空。

代碼

class Node(): ’創建節點’ def __init__(self, data): self.data = data self.next = Noneclass LinkList(): ’創建列表’ def __init__(self, node): ’初始化列表’ self.head = node #鏈表的頭部 self.head.next = None self.tail = self.head #記錄鏈表的尾部 def add_node(self, node): ’添加節點’ self.tail.next = node self.tail = self.tail.next def view(self): ’查看列表’ node = self.head link_str = ’’ while node is not None: if node.next is not None:link_str += str(node.data) + ’-->’ else:link_str += str(node.data) node = node.next print(’The Linklist is:’ + link_str) def length(self): ’列表長度’ node = self.head count = 1 while node.next is not None: count += 1 node = node.next print(’The length of linklist are %d’ % count) return count def delete_node(self, index): ’刪除節點’ if index + 1 > self.length(): raise IndexError(’index out of bounds’) num = 0 node = self.head while True: if num == index - 1:break node = node.next num += 1 tmp_node = node.next node.next = node.next.next return tmp_node.data def find_node(self, index): ’查看具體節點’ if index + 1 > self.length(): raise IndexError(’index out of bounds’) num = 0 node = self.head while True: if num == index:break node = node.next num += 1 return node.datanode1 = Node(3301)node2 = Node(330104)node3 = Node(330104005)node4 = Node(330104005052)node5 = Node(330104005052001)linklist = LinkList(node1)linklist.add_node(node2)linklist.add_node(node3)linklist.add_node(node4)linklist.add_node(node5)linklist.view()linklist.length()

以上就是python如何對鏈表操作的詳細內容,更多關于python 鏈表操作的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 日韩欧美国产高清在线观看 | 在线视频日韩精品 | 国内一区 | 国产日韩欧美在线 | 一级做性色a爰片久久毛片 一级做性色a爰片久久毛片免费 | 99re热视频 | 中文字幕亚洲精品第一区 | 日本高清无吗免费播放 | 欧美视频在线一区 | 一区在线免费 | 日本成a人伦片 | 91久久国产综合精品 | 成人中文字幕一区二区三区 | 久色一区 | 颜值超高的女神啪啪 | 日本www高清| 国产成年女一区二区三区 | 九九在线精品视频播放 | 欧美特级午夜一区二区三区 | 亚欧美视频 | 欧美另类久久久精品 | 荡女妇边被c边呻吟久久 | 高清一级毛片免免费看 | 黄色成人毛片 | 做爰www免费看视频 1024色淫免费视频 | avtom影院入口永久在线观看 | 男人的天堂在线精品视频 | 日本人在线看片 | 韩日黄色 | 成人午夜大片免费看爽爽爽 | 国产成人免费视频精品一区二区 | 欧美日韩精品在线播放 | 国产精品va一级二级三级 | 99精品国产高清一区二区三区香蕉 | 精品国产免费人成在线观看 | 精品国产三级a | 碰碰碰精品视频在线观看 | 99精品国产高清一区二区三区香蕉 | 日本欧美视频 | 分享一个无毒不卡免费国产 | 免费看成人 |