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

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

python操作鏈表的示例代碼

瀏覽:5日期: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 編程
相關文章:
主站蜘蛛池模板: 上思县| 商丘市| 永福县| 涟源市| 游戏| 大英县| 庄浪县| 锡林浩特市| 博湖县| 定襄县| 镇康县| 泸州市| 沁阳市| 土默特左旗| 汝南县| 行唐县| 星座| 信丰县| 乌海市| 广东省| 塘沽区| 泌阳县| 措勤县| 承德县| 宁津县| 三穗县| 海城市| 仙桃市| 松滋市| 盈江县| 武邑县| 福安市| 汶上县| 会泽县| 曲水县| 昌都县| 宁津县| 沛县| 贺兰县| 南川市| 玉树县|