久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

python操作鏈表的示例代碼

瀏覽:4日期:2022-07-09 17:20:19

class Node: def __init__(self,dataval=None): self.dataval=dataval self.nextval=Noneclass SLinkList: def __init__(self): self.headval=None # 遍歷列表 def traversal_slist(self): head_node=self.headval while head_node is not None: print(head_node.dataval) head_node=head_node.nextval# 表頭插入結點 def head_insert(self,newdata): Newdata=Node(newdata) Newdata.nextval=self.headval self.headval=Newdata # 表尾插入結點 def tail_insert(self,newdata): Newdata=Node(newdata) if self.headval is None: self.headval=Newdata return head_node = self.headval while head_node.nextval : head_node=head_node.nextval head_node.nextval=Newdata# 在兩個數據結點之間插入 def middle_insert(self,middle_node,newdata): Newdata=Node(newdata) if middle_node is None: return Newdata.nextval=middle_node.nextval middle_node.nextval=Newdata# 刪除結點 def remove_node(self,newdata): head_node=self.headval if head_node==None: return if head_node.dataval == newdata: self.headval = head_node.nextval head_node = None return while head_node is not None: prev=head_node head_node=head_node.nextval if head_node:if head_node.dataval==newdata: prev.nextval=head_node.nextval lis=SLinkList()lis.headval=Node(’aa’)ee=Node(’bb’)lis.headval.nextval=eelis.head_insert(’cc’)lis.tail_insert(’dd’)lis.middle_insert(ee,'Fri')lis.remove_node(’bb’)lis.traversal_slist()

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

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 基隆市| 崇仁县| 社旗县| 唐河县| 阿克| 香河县| 柳州市| 金堂县| 阳春市| 错那县| 南漳县| 屏南县| 大渡口区| 水富县| 黄梅县| 盐亭县| 吴忠市| 治多县| 博乐市| 望奎县| 庐江县| 陇南市| 周口市| 盱眙县| 闸北区| 灌阳县| 司法| 阳朔县| 塘沽区| 靖宇县| 江油市| 宝鸡市| 唐海县| 鄂尔多斯市| 林口县| 嘉善县| 日土县| 咸丰县| 巨野县| 登封市| 临邑县|