python实现单链表

# coding:utf-8 class node: def __init__(self, value): self.data = value self.next = none class linklist: def __init__(self, data=[0]): self.head = none self.init_link_list(data) # 初始化链表 # data 为数组 def init_link_list(self, data): if len(data) == 0: print(“initialization data is null”) return self.head = node(data[0]) current = self.head for index in data[1:]: current.next = node(index) current = current.next # 获取当前结点 def get_node(self, index): if self.is_empty(): print(“link is empty”) return if index > self.get_length() or index self.get_length() or index

Posted in 未分类

发表评论