Fix LinkedList.push and .element methods

This commit is contained in:
Alexey Andreev 2015-10-08 19:59:38 +03:00
parent a4e41fc6be
commit 4082c6389a
2 changed files with 15 additions and 3 deletions

View File

@ -140,7 +140,10 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
@Override
public E element() {
return null;
if (firstEntry == null) {
throw new TNoSuchElementException();
}
return firstEntry.item;
}
@Override
@ -273,12 +276,12 @@ public class TLinkedList<E> extends TAbstractSequentialList<E> implements TDeque
@Override
public void push(E e) {
add(e);
addFirst(e);
}
@Override
public E pop() {
return removeLast();
return removeFirst();
}
@Override

View File

@ -214,4 +214,13 @@ public class LinkedListTest {
assertEquals(4, list.size());
assertArrayEquals(new String[] { "1", "2", "3", "1" }, list.toArray(new String[0]));
}
@Test
public void pushes() {
LinkedList<String> list = new LinkedList<>();
list.push("foo");
assertEquals("foo", list.peek());
list.push("bar");
assertEquals("bar", list.peek());
}
}