Today we are moving forward with our Linked Lists and for today our aims are to get a size of the list and get a first element. I highly recommend for you to read the previous parts about Linked Lists since it’s very important to cover all the basics that I mentioned before and all code will be more understandable. If you feel great to continue, just let’s do this.
Link to previous blogpost:
Function → “size()” , and it should return integer
Returns the number of nodes in the linked list.
const list = new LinkedList();
list.insertFirst(‘a’);
list.insertFirst(‘b’);
list.insertFirst(‘c’);
list.size(); //returns 3
weSize function in LInked List Class
We created a size method in the “Linked List” class. We assigned “head” pointing to the node(if created this node of course) and also we created “counter”. While “node.next” is not null we will count how many nodes we have.
#linked-lists #algorithms #javascript #data-structures #software-development #programming