update: fix insert
This commit is contained in:
parent
7858b01653
commit
8a0c6785c5
@ -59,7 +59,13 @@ public class LinkedList {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void insert(Object content) {
|
||||
public void insert(Object content, Object prev) {
|
||||
toFirst();
|
||||
|
||||
while(current.getContent() != prev && hasAccess()) {
|
||||
toNext();
|
||||
}
|
||||
|
||||
if (hasAccess()) {
|
||||
Node newNode = new Node(content);
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ public class Main {
|
||||
System.out.println("Append:");
|
||||
linkedList.append(weapon1);
|
||||
System.out.println("Insert:");
|
||||
linkedList.insert(weapon2);
|
||||
linkedList.insert(weapon2, weapon1);
|
||||
System.out.println(linkedList.getSize());
|
||||
System.out.println(linkedList.hasAccess());
|
||||
System.out.println("Append:");
|
||||
@ -20,8 +20,8 @@ public class Main {
|
||||
linkedList.toFirst();
|
||||
linkedList.toLast();
|
||||
linkedList.toNext();
|
||||
System.out.println(linkedList.getFirst());
|
||||
System.out.println(linkedList.getLast());
|
||||
System.out.println("First: " + linkedList.getFirst());
|
||||
System.out.println("Last: " + linkedList.getLast());
|
||||
|
||||
linkedList.remove();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user