I'm looking to use a method that takes in the information of an object, creates an instance of the object, sets the information, then it creates a node and sets the information to the node, and finally inserts the node into my linked list where it belongs. The linked list only has to be organized by the rfidTag
String
type which is a 9-digit hexadecimal representation. Here is what I have so far (I've ignored the "by rfidTag" part)...
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);
}
}
Now I don't have the slightest clue as to what to put, but I'll show you what I've tried and add comments as to where I am lost and looking to accomplish...
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
}
I AM CURRENTLY TRYING TO GET MY OTHER ATTEMPTS TO RUN WITHOUT THROWING EXCEPTIONS! WILL ADD WHEN FINISHED!