我正在寻找使用一种方法,它接收对象的信息,创建对象的实例,设置信息,然后创建节点并将信息设置到节点上,最后将节点插入到它所属的链接列表中。链表只能由rfidTag
String
类型组织,它是一个9位十六进制表示。以下是我迄今为止(我忽略了“由rfidTag”部分)...插入节点到链接列表
public class ItemList {
ItemInfoNode head;
ItemInfoNode tail;
ItemInfoNode cursor;
int listCount = 0;
public ItemList(){
head = cursor = tail = null;
}
public void insertInfo(String name, String rfidTag, String initPosition,
double price) {
ItemInfo obj = new ItemInfo(name, rfidTag, initPosition, initPosition, price);
ItemInfoNode temp = new ItemInfoNode();
temp.setInfo(obj);
}
}
现在我没有丝毫线索,放什么做的,但我会告诉你我已经试过并添加注释,以我在哪里丢失,并且希望完成...
ItemInfo obj = new ItemInfo(name, rfidTag, initPosition, initPosition, price);
ItemInfoNode temp = new ItemInfoNode();
temp.setInfo(obj);
if (head == null) {
head = temp;
cursor = temp;
tail = temp;
head.setNext(cursor);
tail.setPrev(cursor);
listCount++;
} else {
cursor = temp;
cursor.setPrev(head);
cursor.setNext(tail);
System.out.println(cursor.getPrev().getInfo().getName());
System.out.println(cursor.getInfo().getName());
System.out.println(cursor.getNext().getInfo().getName());
// Now I stop here because I do not understand how to put a 3rd in
// between my head and tail without losing the middle nodes info (cursor)
// These printlns are here to help me understand what exactly is happening!
// So I am rather unclear one what my next step should be
}
目前我正在试图让我的其他尝试运行没有出现任何例外!完成后会添加!
是否有任何理由不能使用ArrayList? –
blearn
2013-02-21 04:02:18
这是一个类,我不能使用任何数据结构,它必须手动进行我想你可以说,但我从来没有像这样使用LinkedLists,也没有使用DLL。此外,我的文本没有帮助我... – Sherifftwinkie 2013-02-21 04:06:46
你是否希望在最后或中间插入元素?你能说出_cursor_的重要性吗?我的意思是它代表什么? – asifsid88 2013-02-21 04:06:48