Assuming that cursor points to the node after which the node is to be inserted.
ItemInfo obj = new ItemInfo(name, rfidTag, initPosition, initPosition, price);
ItemInfoNode temp = new ItemInfoNode();
temp.setInfo(obj);
if(head == null){
head = tail = cursor = tmp;
}
else{
if(cursor == tail)
{
cursor.setNext(tmp);
tmp.setPrev(cursor);
tail = tmp;
}
else
{
tmp.setNext(cursor.getNext());
tmp.setPrev(cursor);
cursor.getNext().setPrev(tmp);
cursor.setNext(tmp);
}
}
listCount++;
With this, if the node is inserted for the first time then All (head, tail and cursor) will point to the first node. If n number of nodes are already present then we need to insert the new node according to the position of the cursor. If cursor points to the tail, then the new node is added at the end and tail is updated. If cursor points to any other node (including head) then the new node is inserted after the cursor and tail is untouched. In both the cases the head is untouched i.e., head will always point to the first node. [Tail will always point to the last node -- and updated accordingly]
Hope this helps!!