public void removeAllKey(int Key){
Node prev = this.head;
Node cur = this.head.next;
while(cur != null) {
if(cur.data == key) {
prev.next = cur.next;
cur = cur.next;
}else {
prev = prev.next;
cur = cur.next;
}
}
if(this.head.data == key) {
this.head = this.head.next;
}
}
删除链表中等于给定值 key 的所有节点
最新推荐文章于 2023-02-11 22:32:00 发布