mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-25 22:46:20 +08:00
Update LinkedList prepend pseudocode and append test (#188)
* Add LinkedList test * Add pseudocode for LinkedList prepend
This commit is contained in:
parent
872521fb03
commit
002d32a8cd
@ -37,7 +37,20 @@ Add(value)
|
||||
end if
|
||||
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
|
||||
|
||||
```text
|
||||
|
@ -16,6 +16,7 @@ describe('LinkedList', () => {
|
||||
linkedList.append(2);
|
||||
|
||||
expect(linkedList.toString()).toBe('1,2');
|
||||
expect(linkedList.tail.next).toBeNull();
|
||||
});
|
||||
|
||||
it('should prepend node to linked list', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user