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 fc4a3aa

Browse files
adding size method
1 parent 2d28cff commit fc4a3aa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

‎linkedList/linkedList.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ class LinkedList {
1515
}
1616

1717
insertFirst(data) {
18-
this.head =new Node(data, this.head);
18+
this.head = new Node(data, this.head);
19+
}
20+
21+
size() {
22+
let counter = 0;
23+
let node = this.head;
24+
while(node) {
25+
counter++;
26+
node = node.next;
27+
}
28+
return counter;
1929
}
2030
}
2131

0 commit comments

Comments
(0)

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