Python单链表逆置
- class Node(object):
- def __init__(self, data=None, next=None):
- self.data = data
- self.next = next
-
- link = Node(1, Node(2, Node(3, Node(4, Node(5, Node(6, Node(7, Node(8, Node(9)))))))))
-
- def rev(link):
- pre = link
- cur = link.next
- pre.next = None
- while cur:
- tmp = cur.next
- cur.next = pre
- pre = cur
- cur = tmp
- return pre
-
- root = rev(link)
- while root:
- print root.data
- root = root.next
解压密码: detechn或detechn.com
免责声明
本站所有资源出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站发布资源来源于互联网,可能存在水印或者引流等信息,请用户自行鉴别,做一个有主见和判断力的用户。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
文章不错非常喜欢