diff --git a/src/data-structures/linked-list/README.md b/src/data-structures/linked-list/README.md index 96527d35..8f1a46c8 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 376a2e01..795bb247 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', () => {