Minor code style fixes for DoublyLinkedList.

This commit is contained in:
Oleksii Trekhleb
2018-07-05 15:44:25 +03:00
parent a72fda4dfd
commit d0499d2544
2 changed files with 21 additions and 6 deletions

View File

@@ -128,6 +128,7 @@ export default class LinkedList {
*/
deleteTail() {
if (this.head === this.tail) {
// There is only one node in linked list.
const deletedTail = this.tail;
this.head = null;
this.tail = null;
@@ -135,6 +136,7 @@ export default class LinkedList {
return deletedTail;
}
// If there are many nodes in linked list...
const deletedTail = this.tail;
// Rewind to the last node and delete "next" link for the node before the last one.
@@ -148,6 +150,7 @@ export default class LinkedList {
}
this.tail = currentNode;
return deletedTail;
}