diff --git a/src/data-structures/linked-list/README.md b/src/data-structures/linked-list/README.md index 95fa7d6634..d583b83e32 100644 --- a/src/data-structures/linked-list/README.md +++ b/src/data-structures/linked-list/README.md @@ -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 diff --git a/src/data-structures/linked-list/__test__/LinkedList.test.js b/src/data-structures/linked-list/__test__/LinkedList.test.js index 376a2e019b..795bb24793 100644 --- a/src/data-structures/linked-list/__test__/LinkedList.test.js +++ b/src/data-structures/linked-list/__test__/LinkedList.test.js @@ -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', () => {