Intelligence Says Russia Offered Taliban Fighters Cash To Kill US Troops

Intelligence Says Russia Offered Taliban Fighters Cash To Kill US Troops. Officials say Trump was briefed on the matter, he denies knowing about it.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Linked List in JavaScript.

What is a data Structure?

A data structure is a way of organizing data that is stored in a computer so that it can be used efficiently.

A Linked List, that as its name says, is a linked list of nodes that are represented by a head that is the first node in the list and the tail that is the last one. Each node has to reference/pointer to the previous and the next node.

The Linked list data structure has two types, the first one is a single linked list, the nodes of this type have a pointer to the next one but for their previous node.

In this article, we are exploring the Single Linked List, that the nodes have a next pointer, not the previous pointer.

Linked List Drawbacks:

In this article, we are going to have a single Linked List data structure.

So we are going to create our two classes :

As you see we are represent two classes. One is Node class in that constructor two parameters that will represent data and next. When every Node class call only one parameter data and next parameter default will be null. The second class has the constructor that will represent head equal to null, and why they are null? Because they don’t have any code in the beginning.

So if we now create, for example:

So we are going to create Insert First() function in Linked List class:

In this insertFirst(), we insert an element in the head of the linked list and the previous element passing through to the insert element next. In this method we are not deleting elements, we are writing insert elements in the head linked list and linked list next passing through the previous element.

So if we now create, for example:

So we are going to create Size() function in the Linked List class:

In this Size(), we are finding out the size of the Linked List. firstly initialize two temporary variables like counter and node. Let counter variable assign to zero and node equals to Linked List head. Using while loop, if the node is present counter will be increment and node will be assigned to node next part of Linked List. When condition false didn’t enter to the loop and return value counter. That will be the size of the Linked List.

So if we now create, for example:

So we are going to create the getFirst() function in the Linked List class:

In this getFirst(), we are returning the first element of the Linked List. By simply returning the head of the Linked List. Because head will be assigned to starting element Linked List.

So if we now create, for example:

So we are going to create getLast() function in the Linked List class:

In this getLast(), we are return the last element of the Linked List. In case first check in Linked list any element is there or not. If element is not there return null, otherwise element is there return last element Linked List. consider temporary variable node assign to head of linked list. Using while loop if there node is there going to the inside loop and again check for node next element. If node next element is not there return node, otherwise node next element is there node will be assigned to the next element of the node. Finally return the last element Linked List.

So we are now create, for example:

So we are going to create clear() function in Linked List:

In this clear(), we are clear the Linked List. In this case simple assign head of the Linked List equal to null.

So we are now create, for example:

So we are going to create removeFirst() in Linked List:

In this removeFirst(),we are going to remove first element in Linked List. So firstly check for the first element in linked list is there or not. If element is not there simple return null, otherwise we using reassign head linked list to the second element of the linked list. Due to first element linked list will over written to the second element of the linked list.

So we are now create, for example:

So we are going to create removeLast() in Linked List:

In this removeLast(),we are going to remove last element in Linked List. So firstly check for the first element in linked list is there or not. If element is not there simple return null, otherwise check for the second element in linked list is there or not. If the no second element in linked list assign first element will be null. In case linked list contains more than two elements. Let consider two temporary like previous and node assign to the first and second elements of linked list respectively. In while loop will used to find out last and previous elements of the linked list.

I hope you like it and it will help to you.

Great courses to learn Data Structures and Algorithms:

Thank you 😃

Add a comment

Related posts:

Product Team Kernel

The smallest group of caring, empowered, competent people who trust each other and are driven by a common mission is what I call the Product Team Kernel. What combination of people make up an ideal…

Outmarked

Having a website today is a must if you have a company or organization, and although social media such as Facebook, Linkedin and MySpace provide opportunities to get in touch with customers and…

Female Hair Loss Causes and Treatments

Consider the head a nursery where the hair is developed rather than plants. As the development of plants relies on the dirt under; the equivalent is the situation with hair. The development of your…