【python】链表的遍历


先定义链表结点类

# 定义结点类
class Node:
	def __init__(self, val):
		self.val = val
		self.next = None

	def traverse(self):
		cur = self
		res = []
		while cur is not None:
			print(cur.val)
			res.append(cur)
			cur = cur.next
		return res


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM