committed by
chris
5 changed files with 178 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<classpath> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
||||
|
<classpathentry kind="src" path="src"/> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> |
||||
|
<classpathentry kind="lib" path="C:/Users/planuser/Downloads/2017_WS_OOP_90.jar"/> |
||||
|
<classpathentry kind="output" path="bin"/> |
||||
|
</classpath> |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>SimpleLinkedList</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
|
</natures> |
||||
|
</projectDescription> |
@ -0,0 +1,45 @@ |
|||||
|
package solution; |
||||
|
|
||||
|
public class Node <E>{ |
||||
|
private Node<E> predecessor; // Vorgänger
|
||||
|
private Node<E> successor; // Nachfolger
|
||||
|
private E payload; // Nutzlast
|
||||
|
|
||||
|
|
||||
|
public Node(E payload) { |
||||
|
this.payload = payload; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public Node<E> getPredecessor() { |
||||
|
return predecessor; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setPredecessor(Node<E> predecessor) { |
||||
|
this.predecessor = predecessor; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public Node<E> getSuccessor() { |
||||
|
return successor; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setSuccessor(Node<E> e) { |
||||
|
this.successor = e; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public E getPayload() { |
||||
|
return payload; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setPayload(E payload) { |
||||
|
this.payload = payload; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,92 @@ |
|||||
|
package solution; |
||||
|
|
||||
|
//2017_OOP_90.jar importieren die von Bayer in der Aufgabenstellung zur Verfügung gestellt wird.
|
||||
|
|
||||
|
import testat.*; |
||||
|
|
||||
|
public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
||||
|
|
||||
|
Node<E> ersteKnoten; |
||||
|
int size; |
||||
|
|
||||
|
public SimpleLinkedList() { |
||||
|
ersteKnoten = null; |
||||
|
size = 0; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int size() { |
||||
|
return size; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean add(E e) { |
||||
|
if (e == null) { |
||||
|
return false; |
||||
|
} else { |
||||
|
Node<E> neuerKnoten = new Node<>(e); |
||||
|
|
||||
|
if (ersteKnoten == null) { |
||||
|
ersteKnoten = neuerKnoten; |
||||
|
} |
||||
|
else { |
||||
|
Node<E> aktuellerKnoten = ersteKnoten; |
||||
|
while(aktuellerKnoten != null) { |
||||
|
aktuellerKnoten = aktuellerKnoten.getSuccessor(); |
||||
|
} |
||||
|
aktuellerKnoten.setSuccessor(neuerKnoten); |
||||
|
aktuellerKnoten.setPredecessor(aktuellerKnoten); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
size++; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean remove(Object o) { |
||||
|
if(o == null) { |
||||
|
return false; |
||||
|
} |
||||
|
Node<E> aktuellerKnoten = ersteKnoten; |
||||
|
while(aktuellerKnoten != null) { |
||||
|
aktuellerKnoten = aktuellerKnoten.getSuccessor(); |
||||
|
} |
||||
|
if(o.equals(aktuellerKnoten)) { |
||||
|
aktuellerKnoten.setPayload(null); |
||||
|
size--; |
||||
|
aktuellerKnoten = aktuellerKnoten.getPredecessor(); |
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean contains(Object o) { |
||||
|
if(o == null) { |
||||
|
return false; |
||||
|
} |
||||
|
Node<E> aktuellerKnoten = ersteKnoten; |
||||
|
while(aktuellerKnoten != null) { |
||||
|
aktuellerKnoten = aktuellerKnoten.getSuccessor(); |
||||
|
} |
||||
|
if(o.equals(aktuellerKnoten)) { |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void forAll(ICommand<E> command) { |
||||
|
if(command != null) { |
||||
|
Node<E> aktuellerKnoten = ersteKnoten; |
||||
|
while(aktuellerKnoten != null) { |
||||
|
command.execute(aktuellerKnoten.getPayload()); |
||||
|
aktuellerKnoten = aktuellerKnoten.getSuccessor(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package solution; |
||||
|
import testat.*; |
||||
|
|
||||
|
public class SimpleLinkedListTest extends SimpleListTest90{ |
||||
|
|
||||
|
@Override |
||||
|
protected ISimpleList<Integer> getInstance1() { |
||||
|
return new SimpleLinkedList<>(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected ISimpleList<Ticket<Integer>> getInstance2() { |
||||
|
return new SimpleLinkedList<>(); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue