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 c258016

Browse files
adding getAt method
1 parent af80c0b commit c258016

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎linkedList/linkedList.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,21 @@ class LinkedList {
8585
this.getLast().next = new Node(data);
8686
}
8787
}
88+
89+
getAt(index) {
90+
let counter = 0;
91+
let node = this.head;
92+
while(node) {
93+
if(counter === index) {
94+
return node;
95+
}
96+
97+
counter++;
98+
node = node.next;
99+
}
100+
101+
return null;
102+
}
103+
88104
}
89105

0 commit comments

Comments
(0)

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