私はこの問題を解決するのに本当に苦労しています。私はそれに何時間も費やしましたが、理解できません。
手動で並べ替えようとしているリンク リストがあります。私のノードは CNodes と呼ばれます。start CNode、tail CNode、および newNext CNode があります。
各ノードには連絡先が含まれています。連絡先には、リストを並べ替えようとしているファーストネームがあります。
これを行うための自動化された方法が他にもあることは知っていますが、並べ替えの方法を理解していることを示す必要があります (この時点では明らかにわかりません)。
各ノードを反復処理し、それを比較して開始し、資格がある場合は開始エンティティを変更することで、これを実行しようとしています。
このコードは機能していません...私は 2 日間このコードに取り組んできましたが、本当に行き詰っています。
具体的な提案をいただければ幸いです。
CNode nextNode=start;
while(nextNode.getNext()!=null) {
CNode newNext;
tail=nextNode;
while(tail!=null) {
if(start.getContact().getStrFirstName().compareTo(tail.getContact().getStrFirstName()) > 0) {
//We put the starting node in a temp node
newNext=start;
newNext.setNext(tail.getNext());
//We set our current node to the start
start=tail;
start.setNext(newNext);
//Set the next node of start to the original next one of the one we
//just removed from the chain
//Set current marker to the new first nodes' next entity
tail=start.getNext();
//Set the next node for the marker to the one we just removed
} else {
tail=tail.getNext();
}
}
nextNode=nextNode.getNext();
}