linkedList done for real
This commit is contained in:
@@ -8,6 +8,7 @@ public class linkedlist
|
|||||||
|
|
||||||
linkedlist()
|
linkedlist()
|
||||||
{
|
{
|
||||||
|
size = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ public class linkedlist
|
|||||||
node inserted =new node(value);
|
node inserted =new node(value);
|
||||||
this.head = inserted;
|
this.head = inserted;
|
||||||
this.tail = inserted;
|
this.tail = inserted;
|
||||||
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@ public class linkedlist
|
|||||||
else if(index <= size/2 || size < 10)
|
else if(index <= size/2 || size < 10)
|
||||||
{
|
{
|
||||||
node current = head;
|
node current = head;
|
||||||
for(int count = 0; count < index-2; count++)
|
for(int count = 0; count < index-1; count++)
|
||||||
current = current.next;
|
current = current.next;
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ class linkedlistTest
|
|||||||
linkedlist L1 = new linkedlist(50);
|
linkedlist L1 = new linkedlist(50);
|
||||||
|
|
||||||
L1.add(49,0);
|
L1.add(49,0);
|
||||||
assertEquals(50, L1.getNode(1).getValue());
|
assertEquals(2,L1.size);
|
||||||
|
assertEquals(50, L1.getNode(2).getValue());
|
||||||
L1.add(30,1);
|
L1.add(30,1);
|
||||||
assertEquals(30, L1.getNode(1).getValue());
|
assertEquals(30, L1.getNode(2).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user