リンクリストからノードを削除しようとしています!リンクリストには、次のデータが保存されています。
aa 1 1 1 1
bb 2 2 2 2
cc 3 3 3 3
私はJavaコードを使用していますが、私のコードは
Node p=first;
for(Node c=first;c!=null;c=c.next){
if(c.data.startsWith(key)){
if(c.next==null){
}
else{
p=c;
}
if(c==first){
first=first.next;
}
else{
p.next=c.next;
}
}
}
このコードはデータ、つまりcc 3 333のみを正しく削除するだけであるという問題が発生しています。削除したいデータを削除できるように、コードの問題点を確認したいと思います。前もって感謝します。