参考操作の問題に直面しています: 最初にこれは値xをとり、X以下の値を持つリンクを削除するコードですが、それは私に不規則な出力を与えます。ヘルプは高く評価されています。単独リンクリスト参照操作
public void rlx (int x){
Link p = head;//Initializing a pointer equal to head
for (Link c = head.next; c!=null;c=c.next) {//Initializing another Pointer with the Condition to termination
if((int)head.data<=x){//If the Value of head< = to X
head=head.next;//Skip the first and assign head to the second
}else if((int)c.data<=x){
p.next=c.next;//P.next skip c by pointing to c.next instead of c;
}
p=c; reinitialize p;
}
}
主な方法:
public static void main(String [] args){
LinkList l = new LinkList();
l.insertLast(1);
l.insertLast(2);
l.insertLast(3);
l.insertLast(4);
l.insertLast(3);
l.insertLast(2);
l.insertLast(1);
l.rlx(3);
System.out.print(l);
}
出力:[4,2]
何が起こっているのかを診断するためにもさらに情報が必要です。私が見ているところでは、データの挿入に問題があるかもしれません。 – Makoto
他のすべての値がx以下であるため、出力結果が[4]である必要があるため、この問題はデータ削除によるものだと思います。私は別のリンクされたリストを使用せずにそれを行うことができると期待した。このクラスは私によって作られており、このメソッドは内部的にあることに注意してください。@ Makoto –