链表系列面试题1

/*
     * 利用递归实现从后到前输出链表
     */
    private static void printNodeFromLastToFirst(ListNode node)
    {
        if (node != null)
        {
            if (node.next != null)
            {
                printNodeFromLastToFirst(node.next);
            }
            System.out.println(node.getValue());
        }
    }


/*
     * 利用pre和next与head进行相互之间的变换实现链表的反转
     */
    private static ListNode ListNodeRe(ListNode head)
    {
        ListNode pre = null;
        ListNode next;
        while (head != null)
        {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        // 最后的head指向的是null,而pre指向的是反转后的第一个节点
        return pre;
    }

原文地址:https://www.cnblogs.com/qingtianBKY/p/8059761.html