为什么在prev.value.compareTo(v)<0
和if(cur.value.compareTo(v)<0
处出现空指针异常错误?
public void insert (T v) {
Node prev = head, cur = head.next;
if(prev==null)
{
prev=head;
}
else if(prev.value.compareTo(v)<0) //v belongs in the front
{
prev.value=v;
prev=prev.next;
}
else
{
//iterate through the list
prev=prev.next;
cur=cur.next;
while(cur!=null)
{
if(cur.value.compareTo(v)<0)
{
prev=cur;
cur=cur.next;
}
}
}
}