Skip to content

Commit 002d32a

Browse files
hanhdttrekhleb
authored andcommittedAug 30, 2018
Update LinkedList prepend pseudocode and append test (#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

+14-1
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

+1
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)
Please sign in to comment.