循環リンクリストについて読んでいました。ここで私はそれがどのように動作するのか分からないコードです。循環リンクリストのインデックスの要素
public int elementAt(int index){
if(index>size){
return -1;
}
Node n = head;
while(index-1!=0){ // this line is unclear for me
n=n.next;
index--;
}
return n.data;
}
私は同じコードを書いたが、このようになります。ここ
public int elementAt(int index){
if(index>size){
return -1;
}
Node n = head;
while(n.size != index){ // here is my change in the code
n=n.next;
}
return n.data;
}
は、全体のコードです:http://algorithms.tutorialhorizon.com/circular-linked-list-complete-implementation/
私は2番目のコードでは、右やっていますか?
ありがとうございました
自分でチェックしたりデバッガを使用してみませんか? – Idos
'' n.size'は何ですか? – Thomas
ここに全体のコードhttp://algorithms.tutorialhorizon.com/circular-linked-list-complete-implementation/ありがとう – Joe