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:

https://medium.com/dev-genius/javascript-linked-lists-create-a-linkedlist-class-api-insert-first-c309f41b24ca

Size of the list

Function → “size()” , and it should return integer

Directions

Returns the number of nodes in the linked list.

Example

const list = new LinkedList();
list.insertFirst(‘a’);
list.insertFirst(‘b’);
list.insertFirst(‘c’);
list.size(); //returns 3

Image for post

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.

Image for post

#linked-lists #algorithms #javascript #data-structures #software-development #programming

JavaScript.Linked Lists. Sizing a list.Get first element in the list
4.10 GEEK