删除指定链表指定位置的元素

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;
	}

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页