public Item delete(int k){
if(isEmpty())
throw new RuntimeException("List is empty");
int i = 1;
Node prev = null, curr = first;
if(size() >= k){
while(i < k){
prev = curr;
curr = curr.next;
i++;
}
if(curr.next == null){
prev.next = null;
last = prev;
}else{
prev.next = curr.next;
curr.next = null;
}
}else{
throw new RuntimeException("k > N");
}
N--;
return curr.item;
}
删除指定链表指定位置的元素
最新推荐文章于 2024-07-29 11:20:43 发布