diff --git a/src/data-structures/linked-list.js b/src/data-structures/linked-list.js index 14e9a23e..ac911c24 100644 --- a/src/data-structures/linked-list.js +++ b/src/data-structures/linked-list.js @@ -258,21 +258,19 @@ if (!this.first || !this.first.next) { return; } - var current = this.first.next; - var prev = this.first; - var temp; - while (current) { - temp = current.next; - current.next = prev; - prev.prev = current; - prev = current; - current = temp; - } - this.first.next = null; - this.last.prev = null; - temp = this.first; - this.first = prev; - this.last = temp; + var current = this.first + var next + + do { + next = current.next + current.next = current.prev + current.prev = next + current = next + } while (next) + + var tmp = this.first + this.first = this.last + this.last = tmp }; })(typeof window === 'undefined' ? module.exports : window);