Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set tail as newNode if currentNode is the tail #1020

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
separate test for offset-based insert
xyn22 committed Apr 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 87c1dde2ab5b8512b88f92949ffeb0ea3d9c2ab6
15 changes: 11 additions & 4 deletions src/data-structures/linked-list/__test__/LinkedList.test.js
Original file line number Diff line number Diff line change
@@ -45,11 +45,18 @@ describe('LinkedList', () => {
linkedList.insert(10, 9);

expect(linkedList.toString()).toBe('1,4,2,3,10');
});

linkedList.insert(7, 5);
expect(linkedList.toString()).toBe('1,4,2,3,10,7');
expect(linkedList.head.toString()).toBe('1');
expect(linkedList.tail.toString()).toBe('7');
it('should insert and maintain head and tail', () => {
const linkedList = new LinkedList();

linkedList.insert(2, 0);
linkedList.insert(3, 1);
linkedList.insert(4, 2);

expect(linkedList.toString()).toBe('2,3,4');
expect(linkedList.head.toString()).toBe('2');
expect(linkedList.tail.toString()).toBe('4');
});

it('should delete node by value from linked list', () => {