美文网首页
单向链表的倒置

单向链表的倒置

作者: 王古 | 来源:发表于2018-10-01 11:14 被阅读0次
        public static class Node {
            public int value;
            public Node next;
    
            public Node(int data) {
                this.value = data;
            }
        }
    
        public static Node reverseList(Node head) {
            Node pre = null;
            Node next = null;
            while (head != null) {
                next = head.next;
                head.next = pre;
                pre = head;
                head = next;
            }
            return pre;
        }
    

    相关文章

      网友评论

          本文标题:单向链表的倒置

          本文链接:https://www.haomeiwen.com/subject/ijqnoftx.html