链表反转

核心:全程保持old_head位置不变,只是将old_head.next位置后移

#!/usr/bin/python
# coding=utf-8

def rotateNode(node):
    if node is None or node.node is None:
        return node
    old_head = node
    current_node = node
    next = node.next
    while next is not None:
        #摘除当前node
        old_head.next = next.next
        next.next = current_node
        current_node = next
        next = old_head.next
    return current_node


你可能感兴趣的:(链表反转)