}
public void inserer(int value) {
- boolean inserted = false;
+ boolean found = false;
if (isEmpty()) {
headNode = new IntNode(value);
list_counter++;
return;
- } else if (value < headNode.getData()) {
- headNode = new IntNode(value, headNode);
- list_counter++;
+ } else if (value == headNode.getData()) {
+ found = true;
return;
} else {
- IntNode nodeCursor = headNode;
IntNode nodeCursorNext = headNode.getNext();
while (nodeCursorNext != null) {
- if (value == nodeCursor.getData() || value == nodeCursorNext.getData()) {
- inserted = true;
- break;
- } else if (value > nodeCursor.getData() && value < nodeCursorNext.getData()) {
- nodeCursor.setNext(new IntNode(value, nodeCursorNext));
- inserted = true;
- list_counter++;
+ if (value == nodeCursorNext.getData()) {
+ found = true;
break;
} else {
- nodeCursor = nodeCursorNext;
nodeCursorNext = nodeCursorNext.getNext();
}
}
- if (!inserted) {
- nodeCursor.setNext(new IntNode(value));
+ if (!found) {
+ headNode = new IntNode(value, headNode);
list_counter++;
}
}