Update LinkedList prepend pseudocode and append test (#188)

* Add LinkedList test

* Add pseudocode for LinkedList prepend
This commit is contained in:
Hanh D. TRAN 2018-08-30 14:43:21 +09:00 committed by Oleksii Trekhleb
parent 872521fb03
commit 002d32a8cd
2 changed files with 15 additions and 1 deletions

View File

@ -37,7 +37,20 @@ Add(value)
end if end if
end Add end Add
``` ```
```text
Prepend(value)
Pre: value is the value to add to the list
Post: value has been placed at the head of the list
n ← node(value)
n.next ← head
head ← n
if tail = ø
tail ← n
end
end Prepend
```
### Search ### Search
```text ```text

View File

@ -16,6 +16,7 @@ describe('LinkedList', () => {
linkedList.append(2); linkedList.append(2);
expect(linkedList.toString()).toBe('1,2'); expect(linkedList.toString()).toBe('1,2');
expect(linkedList.tail.next).toBeNull();
}); });
it('should prepend node to linked list', () => { it('should prepend node to linked list', () => {