首页 > 代码库 > 【剑指offer】Q5:从尾到头打印链表

【剑指offer】Q5:从尾到头打印链表

可以练习下链表的逆置。

def PrintListReversingly(head):
	if head == None:
		return
	if head:
		PrintListReversingly(head.next)
	print head.val


def reverse(head):
	if head == None or head.next == None:
		return head
	psuhead = ListNode(-1)
	while head:
		nexthead = head.next
		head.next = psuhead.next
		psuhead.next = head
		head = nexthead
	head = psuhead.next
	del psuhead
	return head