I have created a class SLList where I'm going to take a doubly linked list SLlist
and I'm trying to find how to add a new node of any type to the start of that doubly linked list.
In order to do this, I have made some sentinels firstsen
and lastsen
since I was told that this approach would be a lot better to do.
Now, as said earlier, I'm trying to add a new node to the start of that doubly linked list using a function public void addFirst(T) {}
.
Here is my code so far...
public class SLList{
private class IntNode<T> {
private int data;
private IntNode previous;
private IntNode next;
public IntNode (int data, IntNode previous, IntNode next) {
this.data = data;
this.previous = previous;
this.next = next;
}
}
IntNode firstsen;
IntNode Lastsen;
public SLList(){
firstsen = new IntNode(0,null,null );
Lastsen = new IntNode(0, firstsen, null);
firstsen.next = Lastsen;
}
public void addFirst(T) {}
}
However, I'm stumped on what I have to do next because I'm new to object oriented programming, so if anyone would be willing to help, that would be really helpful.
Furthermore, I would also appreciate if anyone could explain how to edit my code to accept any generic type
Thank you, Dave