List in data structure is an ordered data structure that stores elements sequentially and can be accessed by index. It is a linear data structure.
Static list is a list that has a fixed length. It is implemented by array.
Pros:
- Access by index is fast.
- It is easy to implement.
Cons:
- It is not easy to insert or delete an element.
- It is not easy to expand the length of the list.
Dynamic list is a list that has a variable length. It is implemented by array and linked list.
Pros:
- It is easy to insert or delete an element.
- It is easy to expand the length of the list.
Cons:
- Access by index is slow.
- It is not easy to implement.
Linked list is a list that stores elements in a node. Each node contains the element and a pointer to the next node. The first node is called the head node, and the last node is called the tail node. The tail node points to null.
+--------+ +--------+ +--------+
| data | | data | | data |
| next | | next | | next |
+--------+ +--------+ +--------+