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){
.
.
.
.
.
.
我必须在链接列表中对赛马的时间记录进行排序
我真的不知道如何编写SortedLinkedList的添加方法......
我上面写了一些代码,以
开头有人可以帮助我吗?
答案 0 :(得分:1)
履行的其他条款:
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
方法应定义为名称所暗示的内容。