linkedList done for real

This commit is contained in:
Libkyy
2022-03-22 08:59:51 +02:00
parent 025a6ee83b
commit 57166f15c9
2 changed files with 6 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ public class linkedlist
linkedlist()
{
size = -1;
}
@@ -16,6 +17,7 @@ public class linkedlist
node inserted =new node(value);
this.head = inserted;
this.tail = inserted;
size = 0;
}
@@ -40,7 +42,7 @@ public class linkedlist
else if(index <= size/2 || size < 10)
{
node current = head;
for(int count = 0; count < index-2; count++)
for(int count = 0; count < index-1; count++)
current = current.next;
return current;
}

View File

@@ -13,9 +13,10 @@ class linkedlistTest
linkedlist L1 = new linkedlist(50);
L1.add(49,0);
assertEquals(50, L1.getNode(1).getValue());
assertEquals(2,L1.size);
assertEquals(50, L1.getNode(2).getValue());
L1.add(30,1);
assertEquals(30, L1.getNode(1).getValue());
assertEquals(30, L1.getNode(2).getValue());
}