class Node {
private int data;
private Node next;
}
public static Node reverseLinkedList(Node head){
if (head == null || head.next == null){
return head;
}
Node first = head;
Node cur = head.next;
Node next;
while(cur != null){
next = cur.getNext();
cur.setNext(first);
first = cur;
cur = next;
}
head.setNext(null);
head = first;
return head;
}
java反转单链表
最新推荐文章于 2022-04-22 23:21:42 发布