Skip to content

Commit 002d32a

Browse files
hanhdttrekhleb
authored andcommitted
Update LinkedList prepend pseudocode and append test (trekhleb#188)
* Add LinkedList test * Add pseudocode for LinkedList prepend
1 parent 872521f commit 002d32a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/data-structures/linked-list/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ Add(value)
3737
end if
3838
end Add
3939
```
40-
40+
41+
```text
42+
Prepend(value)
43+
Pre: value is the value to add to the list
44+
Post: value has been placed at the head of the list
45+
n ← node(value)
46+
n.next ← head
47+
head ← n
48+
if tail = ø
49+
tail ← n
50+
end
51+
end Prepend
52+
```
53+
4154
### Search
4255

4356
```text

src/data-structures/linked-list/__test__/LinkedList.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('LinkedList', () => {
1616
linkedList.append(2);
1717

1818
expect(linkedList.toString()).toBe('1,2');
19+
expect(linkedList.tail.next).toBeNull();
1920
});
2021

2122
it('should prepend node to linked list', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy