# 用Python实现简单的单向链表中实现append和iternodes功能时出现的一个小问题

class Node:
def __init__(self,item,next = None,prev = None):
self.item = item
self.next = next
self.prev = prev

def __repr__(self):
return '{} --> {}'.format(self.item ,self.next.item if self.next else None)

def __init__(self):
self.tail = None

def apend(self,item):
node = Node(item) #执行apend 实例化Node
tail = self.tail
if tail is None:
else:
tail.next = node
self.tail = node
return self

def __repr__(self):
pass

def iternodes(self):
while current:
yield current
current = current.next

ll.apend('begin').apend('a').apend('b').apend('c').apend('end')
for x in ll.iternodes():
print(x)

class Node:
def __init__(self,item,next = None,prev = None):
self.item = item
self.next = next
self.prev = prev

def __repr__(self):
return '{} --> {}'.format(self.item,self.next.item if self.next else None)

def __init__(self):
self.tail = None

def append(self,item):
n = Node(item)
tail = self.tail
else:
tail.next = n
tail = n
return self

def iternodes(self):
while current:
yield current
current = current.next

ll.append('begin').append('1').append('2').append('3').append('end')
for x in ll.iternodes():
print(x)

----------没有实现

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120