我正在寻找一种方法来获取对象的信息,创建对象的实例,设置信息,然后创建节点并将信息设置到节点,最后将节点插入我的链表它所属的地方。链表只需按rfidTag
String
9 位十六进制表示的类型进行组织。这是我到目前为止所拥有的(我忽略了“by 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
}
我目前正在尝试让我的其他尝试运行而不抛出异常!完成后会添加!