Created
April 21, 2019 15:30
-
-
Save jdgo-mars/34c4c48e3b76d74d7071a747b56cdbef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LinkList { | |
constructor(value) { | |
this._head = { value, next: null }; | |
this._tail = this._head; | |
} | |
insert(value) { | |
//update tail as needed | |
const node = { value, next: null }; | |
this._tail.next = node; | |
this._tail = node; | |
} | |
removeTail() { | |
let currentNode = this._head; | |
// if we reach the 2nd last node stop | |
while (currentNode.next != this._tail) { | |
// we assign the next to the currentNode | |
currentNode = currentNode.next; | |
} | |
// reset next node to null | |
currentNode.next = null; | |
// tail is now the 2nd latest node | |
this._tail = currentNode; | |
} | |
isHead() {} | |
isTail() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment