反转链表

package com.imust;

class Node {
    public int value;
    public Node next;

    public Node(int data) {
        this.value = data;
    }
}
public class ReverseList {
    public static void reverseList(Node head) {
        if (head == null || head.next == null)
            return;
        Node pre = null;//先前节点
        Node next = null;//临时节点
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }

    }
}
https://www.bilibili.com/video/av49762694?from=search&seid=8970664744949276024
posted @ 2019-11-22 20:19  单词计数程序大牛  阅读(105)  评论(0编辑  收藏  举报