Skip to content

Commit fc4a3aa

Browse files
committed
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)