Java实现单链表的反转
public static class Node {
public int value;
public Node next;
public Node(int data) {
value = data;
}
}
public static Node reverseLinkedList (Node head){
Node pre = null;
Node next = null;
while (head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
public int value;
public Node next;
public Node(int data) {
value = data;
}
}
public static Node reverseLinkedList (Node head){
Node pre = null;
Node next = null;
while (head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
全部评论
相关推荐
11-10 22:06
上海震旦职业学院 前端工程师 点赞 评论 收藏
分享