-
Java double linked list
Hi huys just wanted to ask if I can use int array as the element of a double linked list. In the constructor below all elements are from Integer type. The problem is that I need to save two ints in one "inhalt"( one for the element itself and one for the reference).
Thanks in advance.
public class Liste<Integer>
{
private Liste <Integer> praefix;
private Integer inhalt;
private Liste <Integer> suffix;
public Liste(Integer e) {
inhalt = e;
praefix = null;
suffix = null;
}
-
That class would make a fine node of a double linked list; just change your notation somewhat:
Code:
public class Liste<T>
{
private Liste <T> praefix;
private T inhalt;
private Liste <T> suffix;
public Liste(T e) {
inhalt = e;
praefix = null;
suffix = null;
}
}
That way the type of the data is T and you can always 'specialize' that type:
Code:
Liste <Integer> head= new Liste<Integer>(new Integer(42));
kind regards,
Jos