mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +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
@ -38,6 +38,19 @@ Add(value)
|
|||||||
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
|
||||||
|
@ -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', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user