2. Topics We are gonna cover
1.What Is Linked List & It's Application
2.Linked List Vs Arrays
3.Creation Of Linked list
4.Insertion Of Linked List
5.Deletion At Link List
6.Searching In Linked List
7.Find Middle Element Of Linked List
3. What Is Linked List
A linked list is a linear data structure, in which the elements are
not stored at contiguous memory locations. The elements in a
linked list are linked using pointers as shown in the below image:
4. Types Of Linked List
There are mainly three types of linked lists:
• Single-linked list
• Double linked list
• Circular linked list
5. Linked List Applications
Applications of linked list in computer science:
1.Implementation of stacks and queues
2.Implementation of graphs: Adjacency list representation of graphs is the
most popular which uses a linked list to store adjacent vertices.
3.Dynamic memory allocation: We use a linked list of free blocks.
4.Maintaining a directory of names
5.Performing arithmetic operations on long integers
Applications of linked list in the real world:
1.Image viewer
2.Previous and next page in a web browser
3.Music Player
4.File Systems
5.Undo/Redo Functionality
12. Insetion At Head
To insert a node at the start/beginning/front of a Linked List, we need to:
• Make the first node of Linked List linked to the new node
• Remove the head from the original first node of Linked List
• Make the new node as the Head of the Linked List.
13. Insertion At Tail
To insert a node at the end of a Linked List, we need to:
• Go to the last node of the Linked List
• Change the next pointer of last node from NULL to the new node
• Make the next pointer of new node as NULL to show the end of Linked
List
14. To insert a node after a given node in a Linked List, we need to:
• Check if the given node exists or not.
⚬ If it do not exists,
■ terminate the process.
⚬ If the given node exists,
■ Make the element to be inserted as a new node
■ Change the next pointer of given node to the new node
■ Now shift the original next pointer of given node to the next pointer of new node
Insert After a Node
15. Deletion Of Node At begining
Point head to the next node i.e. second node
temp = head
head = head->next
Make sure to free unused memory
free(temp); or delete temp;
17. • Finding anelement
• Initialize a node pointer, current = head.
• Do following while current is not NULL
⚬ If the current value (i.e., current->key) is equal to the key being
searched return true.
⚬ Otherwise, move to the next node (current = current->next).
• If the key is not found, return false
19. Traverse linked list using two-pointers. Move one pointer by one and the
other pointers by two. When the fast pointer reaches the end, the slow
pointer will reach the middle of the linked list.
Below image shows how printMiddle function works in the code :