NullPointerException,而反向链表。谁能解释我为什么我在这里得到一个空指针异常。我是编码新手。这是我要在IDE中运行的一些代码段。
public static LinkedList reverse(LinkedList list){
if(list.head==null || list.head.next==null){
return list;
}
Node curr = list.head;
Node prev = null;
while(curr.next != null){
curr.next.next = curr;
curr.next = prev;
prev = curr;
curr = curr.next;
}
list.head = curr;
return list;
}