# What Data Structure Is Used in List?

//

Larry Thompson

In programming, a data structure is a way of organizing and storing data to efficiently perform operations on it. One commonly used data structure is the list. A list is an ordered collection of elements, where each element has a unique position or index.

## Types of Lists

There are different types of lists in programming, including:

• Array Lists: Also known as dynamic arrays, these lists can grow or shrink in size as elements are added or removed.
• Linked Lists: In linked lists, each element contains a reference to the next element in the list. This allows for efficient insertions and deletions but requires extra memory for storing the references.
• Doubly Linked Lists: Similar to linked lists, doubly linked lists also have a reference to the previous element in addition to the next element. This enables bidirectional traversal and easier removal of elements.

## List Operations

A list supports various operations that allow manipulation and retrieval of its elements. Some common operations include:

• Accessing Elements: Elements in a list can be accessed by their index. For example, to access the third element of a list, you would use list[2].
• Inserting Elements: New elements can be inserted at any position within a list.

Existing elements are shifted to make room for the new element.

• Removing Elements: Elements can be removed from a list by specifying their index. The remaining elements will be shifted to fill the gap.
• Finding Length: A list has a length property that indicates the number of elements it contains.

## Examples

Let’s take a look at some examples to understand how lists are used in programming:

### Example 1: Array List

In this example, we create an array list and perform some basic operations:

``````
const fruits = ["apple", "banana", "orange"];

console.log(fruits[0]); // Output: "apple"

fruits.push("grape");
console.log(fruits); // Output: ["apple", "banana", "orange", "grape"]

fruits.splice(1, 1);
console.log(fruits); // Output: ["apple", "orange"]
```
```

This example demonstrates a linked list implementation:

``````
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}

constructor() {
}

const newNode = new Node(data);

} else {
while (current.next) {
current = current.next;
}
current.next = newNode;
}
}
}