Error message here!

Hide Error message here!

Error message here!

Hide Error message here!

Error message here!

Close

## 关于单链表反转的一点整理

lukely 2019-08-13 23:46:00 阅读数:9 评论数:0 点赞数:0 收藏数:0

``` public void reversList(){
Node pre = null;
Node next = null;
}
}```

核心的代码就是这一段：

``` Node [data=4, next=Node [data=3, next=Node [data=2, next=Node [data=1, next=Node [data=null, next=null]]]]]
Node [data=3, next=Node [data=2, next=Node [data=1, next=Node [data=null, next=null]]]]
Node [data=2, next=Node [data=1, next=Node [data=null, next=null]]]
Node [data=1, next=Node [data=null, next=null]]
Node [data=null, next=null]```

``` System.out.println(list.getHead());

``` Node [data=null, next=Node [data=1, next=Node [data=2, next=Node [data=3, next=Node [data=4, next=null]]]]]
Node [data=1, next=Node [data=2, next=Node [data=3, next=Node [data=4, next=null]]]]
Node [data=2, next=Node [data=3, next=Node [data=4, next=null]]]
Node [data=3, next=Node [data=4, next=null]]
Node [data=4, next=null]```

`Node [data=4, next=Node [data=3, next=Node [data=2, next=Node [data=1, next=Node [data=null, next=null]]]]]`

`Node [data=1, next=Node [data=null, next=null]]`

```  public void reversList(){
Node pre = new Node(null);
//Node pre = null;错误写法
Node next = null;

}

}```

```public void reversList(){
Node next = null;//用于保存下一个节点

while(temp != null){
next = temp.next;//保存当前节点的下一个节点