else: return True def find_middle_node(head): if not head: return None jump_one = jump_two = head while can_jump_two(jump_two): jump_two = jump_two.next.next jump_one = jump_one.next return jump_one.value if __name__ == '__main__': import random from linked_list import Node l = [] for i in range(11): l.append(random.randint(0, 100)) head = Node.new(l) head.bianli() print 'the %dth to end: %d' % (3, find_kth_to_end(head, 3)) print 'the %dth to end: %d' % (11, find_kth_to_end(head, 11)) # print 'the %dth to end: %d' % (15, find_kth_to_end(head, 15)) print 'the middle of list: %d' % (find_middle_node(head))