1.4 KiB
1.4 KiB
Linked List
Description
LinkedList is a data structure in which data is stored in a linear manner. It usually contains a data field and a link to the memory location of the next mode.
Structure
class LinkedList<E>{
E value;
LinkedList next;
}
The next
variable points to the next node in the data structure and value stores the data. Any number of nodes can be linked in this manner. The structure will be:
Properties
- Linked list does not provide indexing like an array. For accessing a node at position
p
, θ(p) nodes need to be accessed. - Main advantage of linked list is addition and removal of nodes near the end and beginning of lists. It can be done just by updating the link (O(1) time)
- Unlike an array, its size is not predefined. So any number of nodes can be appended.
File descriptions:
CircleLinkedList.java
: A circular linked list where next pointer of last node points to first nide of linked list.SinglyLinkedList.java
: The classic case of single links.CountSinglyLinkedListRecursion.java
: Recursively counts the size of a list.detect_and_create_loop.java
: Detect a loop in linked listDoublyLinkedList.java
: A modification of singly linked list which has aprev
pointer to point to the previous node.Merge_K_SortedLinkedlist.java
: Merges K sorted linked list with mergesort (mergesort is also the most efficient sorting algorithm for linked list).