I have a class SLList
where a doubly linked list SLList
would be taking in values of any generic type.
I have used sentinels to help myself in working with these, and here is my code so far:
public class SLList<T> {
private class IntNode {
private T data;
private IntNode previous;
private IntNode next;
public IntNode(T data, IntNode previous, IntNode next) {
this.data = data;
this.previous = previous;
this.next = next;
}
public IntNode() {
next = previous = this;
}
}
IntNode sentinel;
public SLList() {
sentinel = new IntNode();
}
public int size() {
int x = 0;
while (sentinel.next != null) {
x++;
}
return x;
}
public String makestring() {
return sentinel.data.toString();
}
}
Now I'm trying to turn my doubly linked list into a string using makestring()
but I'm confused on how can I implement this properly into code. Can anyone please explain what am I doing wrong?
Also, if anyone can see if my size()
function is wrong, please feel free to correct me