Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e8654f

Browse files
Remove tail
1 parent a0e195d commit 7e8654f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

‎linkedList.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ LinkedList.prototype.removeHead = function() {
3232
return val;
3333
}
3434

35+
LinkedList.prototype.removeTail = function() {
36+
if(!this.tail) return null;
37+
let val = this.tail.value;
38+
this.tail = this.tail.prev;
39+
if(this.tail) this.tail.next = null;
40+
else this.head = null;
41+
return val;
42+
}
43+
3544
let ll = new LinkedList();
3645

37-
ll.addToHead(1000);
38-
ll.addToHead(2000);
39-
ll.addToTail(3000);
46+
ll.addToHead('one');
47+
ll.addToHead('two');
48+
ll.addToHead('three');
4049

41-
ll.removeHead();
42-
console.log(ll.removeHead());
50+
console.log(ll.removeTail());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /