Linking nodes/adding node data
I need to insert an element into a doubly linked node list. I'm confused, though, with generics.
The method header I'm working with says public void insertBefore (E placeholder, E data)
I'm supposed to insert a new element (data) into the position before an element searched for (placeholder).
I understand how I would go about doing this if placeholder and data were declared as nodes, but I'm rather confused when they're generic E datatypes.
pseudocode seems like something like this:
create new Node new
set new to currentNodes previous
set new's next to placeholder
set placeholder's previous to new
..something along those lines. Yet I can't quite figure out where to get started setting nodes to generic data types, since that doesn't allow use of .previous and .next ... =/
this is all I have come up with, and ... yeah.
public void insertBefore (E placeholder, E data)
Node current = head;
Node previous = null;
Node temp = null
while (current != null && !current.containsData(placeholder))
previous = current;
current = current.next;
previous.next = temp;