I wanted to make a generic method for appending a copy of two linked list together and putting it in another linked list. list a and list b in list c.
here is the code that I have so far.
public static LinkedSequence<?> concatenaton(LinkedSequence<?> s1, LinkedSequence<?> s2) throws java.lang.NullPointerException
{
// Create a new sequence that contains all the elements from one sequence followed by another.
LinkedSequence<?> concat = new LinkedSequence();
if(s1 == null || s2 == null) {
return null;
}
else {
LinkedSequence h1;
LinkedSequence h2;
h1 = s1.clone();
h2 = s2.clone();
concat.addAll(h1);
concat.addAll(h2);
}
return concat;
}
public LinkedSequence<T> clone() {
// Generate a copy of this sequence.
LinkedSequence<T> copy = new LinkedSequence<T>();
//Node<T> newNode = new Node<T>(element);
Node<T> curr = first;
if(getCurrent() == null) {
return null;
} else {
while(curr != null) { //iterate through current list
copy.addLast(curr.getValue());
curr = curr.getLink();
}
}
return copy;
}
public void addLast(T element) {
Node<T> newNode = new Node<T>(element);
if (isCurrent() == false) {
current = newNode;
first = newNode;
last = newNode;
}
else {
//Node newNode = new Node(element);
last.setLink(newNode);
last = newNode;
}
}
the clone copies the whole list in a new list. I keep getting an error saying that I make a generic type in a static type.