Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- insertAt(data, index) {
- if (!this.head) {
- this.head = new Node(data)
- return;
- }
- if (index === 0) {
- this.head = new Node(data, this.head)
- return;
- }
- const previous = this.getAt(index - 1) || this.getLast()
- const node = new Node(data, previous.next)
- previous.next = node
- }
Add Comment
Please, Sign In to add comment