public static void main(String[] args) {
Node node = new Node();
node.setValue(1);
node.setNext(new Node(2,new Node(4,new Node(2,new Node(2,new Node(3,null))))));
int value = 2;
Node newLiking = deleteNumByLinking(node,value);
}
private static Node deleteNumByLinking(Node head,int value) {
if (null == head) {
return null;
}
while (head.getValue() == value){
head = head.getNext();
}
Node cur = head;
Node pre = head;
while (cur!=null){
if (cur.getValue() == value) {
pre.setNext(cur.getNext()) ;
} else {
pre = cur;
}
cur = cur.getNext();
}
return head;
}
删除链表节点中的某个数
最新推荐文章于 2024-09-04 20:55:34 发布