python单向链表的实现
pythob实现单向链表:
class Node:
def __init__(self,item=None,next=None)
self.data = item
self.next = next
class SingleList:
def __init__(self,top=None)
self.top=top
def add(self,item):
node = Node(item)
if not self.top:
self.top = node
else:
tem_list=[]
tem_list.append(self.top)
while True:
cur_node = tem_list.pop(0)
if not cur_node.next :
cur_node.next = node
else:
tem_list.append(cur_node.next)
浙公网安备 33010602011771号