public void add(Racer o) {
LinkedListNode added = new LinkedListNode(o);
LinkedListNode first = head;
LinkedListNode last = tail;
Racer First = (Racer) first.getElement();
Racer Added = (Racer) added.getElement();
Racer Last = (Racer) last.getElement();
if (First.time >= Added.time) {
added.setNext(head);
head = added;
}
else {
while(true){
.
.
.
.
.
.
我必须在链表中对赛马的时间记录进行排序
我真的不知道如何编码我的排序链接列表的添加方法......
我在上面写了一些代码来开始
谁能帮我?
已实现的 else 子句:
else {
LinkedListNode pre = first;
LinkedListNode node = first.getNextNode();
while(true){
if(node == null || node.getElement().time >= added.getElement().time) break;
pre = node;
node = node.getNext();
}
pre.setNext(added);
added.setNext(node);
if(node == null) tail = added;
}
请注意,getNext
和 setNext
方法应定义为名称所暗示的内容。