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 4e59e81

Browse files
adding getFirst, getLast and clear method to linkedList
1 parent fc4a3aa commit 4e59e81

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎linkedList/linkedList.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,28 @@ class LinkedList {
2727
}
2828
return counter;
2929
}
30+
31+
getFirst() {
32+
return this.head;
33+
}
34+
35+
getLast() {
36+
if(!this.head) {
37+
return null;
38+
}
39+
40+
let node = this.head;
41+
while(node) {
42+
if(!node.next) {
43+
return node;
44+
}
45+
46+
node = node.next;
47+
}
48+
49+
clear() {
50+
this.head = null;
51+
}
52+
}
3053
}
3154

0 commit comments

Comments
(0)

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