Java:
public class Element {
private String name;
private Element next;
public Element(String name, Element e) {
this.name=name;
this.next=e;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public Element getNext() {
return next;
}
public void setNext(Element e) {
this.next=e;
}
}
Code:
public class Test{
public static void main (String[]args) {
Element drei = new Element("Müller",new Element("Mustermann",new Element("Schneider",null)));
}
}
Code:
public void insertAt(int destinationIndex,Element toInsert) {
int currentIndex = 1;
Element current = this;
System.out.println(current.getName());
System.out.println(current.getNext().getName());
while(currentIndex<destinationIndex) {
current = current.getNext();
currentIndex++;
}
Element orginalNext = current.getNext();
System.out.println(orginalNext.getName());
current.setNext(toInsert);
toInsert.setNext(orginalNext);
}