From 68ab31308f1bc8061575926d57f98b986e6b9ca0 Mon Sep 17 00:00:00 2001 From: Hanh Tran Date: Mon, 27 Aug 2018 17:55:10 +0900 Subject: [PATCH 1/2] Add LinkedList test --- src/data-structures/linked-list/__test__/LinkedList.test.js | 1 + 1 file changed, 1 insertion(+) 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', () => { From 69505f1d4cf960ed6b4de0b992c8a2115063d533 Mon Sep 17 00:00:00 2001 From: "Hanh D. TRAN" Date: Mon, 27 Aug 2018 23:37:21 +0900 Subject: [PATCH 2/2] Add pseudocode for LinkedList prepend --- src/data-structures/linked-list/README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/data-structures/linked-list/README.md b/src/data-structures/linked-list/README.md index b0e5eaf934..c05c24af4e 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