Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6fdce4a

Browse files
Merge pull request #9 from amejiarosario/feat-improve-linked-list-insert-middle-docs
fix(linked-list): insert in the middle bug
2 parents 2c57521 + f8bd4fd commit 6fdce4a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

‎src/data-structures/linked-lists/linked-list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class LinkedList {
9696
newNode.next = current; // <5>
9797

9898
current.previous.next = newNode; // <6>
99-
if(current.next){current.next.previous = newNode;} // <7>
99+
current.previous = newNode; // <7>
100100
this.size += 1;
101101
return newNode;
102102
}

‎src/data-structures/linked-lists/linked-list.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ describe('LinkedList Test', () => {
165165
it('should insert at the middle', () => {
166166
const newNode = linkedList.add('middle', 1);
167167
expect(newNode.value).toBe('middle');
168+
// checking the 4 surrounding links were updated
168169
expect(newNode.next.value).toBe('found');
169170
expect(newNode.previous.value).toBe(0);
171+
expect(linkedList.get(0).next.value).toBe('middle');
172+
expect(linkedList.get(2).previous.value).toBe('middle');
173+
170174
expect(linkedList.size).toBe(3);
171175
expect(linkedList.first.value).toBe(0);
172176
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /