|
|
@ -1,9 +1,5 @@ |
|
|
|
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> firstNode; |
|
|
@ -23,20 +19,21 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
|
|
|
public boolean add(E e) { |
|
|
|
if (e == null) { |
|
|
|
return false; |
|
|
|
} else if (firstNode == null) { |
|
|
|
firstNode = new Node<E>(e); |
|
|
|
} else { |
|
|
|
Node<E> newNode = new Node<>(e); |
|
|
|
|
|
|
|
if (firstNode == null) { |
|
|
|
firstNode = newNode; |
|
|
|
} else { |
|
|
|
Node<E> currentNode = firstNode; |
|
|
|
while (currentNode != null) { |
|
|
|
currentNode = currentNode.getSuccessor(); |
|
|
|
Node<E> currentNode = firstNode; |
|
|
|
while (currentNode != null) { |
|
|
|
if (currentNode.getSuccessor() == null) { |
|
|
|
break; |
|
|
|
} |
|
|
|
currentNode.setSuccessor(newNode); |
|
|
|
currentNode.setPredecessor(currentNode); |
|
|
|
currentNode = currentNode.getSuccessor(); |
|
|
|
} |
|
|
|
Node<E> newNode = new Node<E>(e); |
|
|
|
currentNode.setSuccessor(newNode); |
|
|
|
newNode.setPredecessor(currentNode); |
|
|
|
} |
|
|
|
|
|
|
|
size++; |
|
|
|
return true; |
|
|
|
} |
|
|
@ -48,14 +45,16 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
|
|
|
} |
|
|
|
Node<E> currentNode = firstNode; |
|
|
|
while (currentNode != null) { |
|
|
|
currentNode = currentNode.getSuccessor(); |
|
|
|
} |
|
|
|
if (o.equals(currentNode)) { |
|
|
|
currentNode.setPayload(null); |
|
|
|
size--; |
|
|
|
currentNode = currentNode.getPredecessor(); |
|
|
|
return true; |
|
|
|
if (o.equals(currentNode.getPayload())) { |
|
|
|
currentNode.setPayload(null); |
|
|
|
size--; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (currentNode.getSuccessor() == null) { |
|
|
|
break; |
|
|
|
} |
|
|
|
currentNode = currentNode.getSuccessor(); |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
@ -67,11 +66,13 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
|
|
|
} |
|
|
|
Node<E> currentNode = firstNode; |
|
|
|
while (currentNode != null) { |
|
|
|
if (o.equals(currentNode.getPayload())) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
currentNode = currentNode.getSuccessor(); |
|
|
|
} |
|
|
|
if (o.equals(currentNode)) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -133,16 +134,14 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
|
|
|
} |
|
|
|
set(0, e); |
|
|
|
|
|
|
|
} else if (size > 0) { |
|
|
|
if (i == size) { |
|
|
|
add(e); |
|
|
|
} |
|
|
|
} else if (i == size) { |
|
|
|
add(e); |
|
|
|
|
|
|
|
} else if (size > 0 && i < size) { |
|
|
|
Node<E> newNode = new Node<>(e); |
|
|
|
Node<E> newNode = new Node<>(e);// node3
|
|
|
|
|
|
|
|
Node<E> tempNode = getIndex(i); |
|
|
|
Node<E> preTempNode = getIndex(i).getPredecessor(); |
|
|
|
Node<E> tempNode = getIndex(i); // node2
|
|
|
|
Node<E> preTempNode = getIndex(i).getPredecessor(); // node1
|
|
|
|
|
|
|
|
preTempNode.setSuccessor(newNode); |
|
|
|
newNode.setPredecessor(preTempNode); |
|
|
|