1. 1
Linked List
Link − Each link of a linked list can store a data
called an element.
Next − Each link of a linked list contains a link to
the next link called Next.
Linked List − A Linked List contains the
connection link to the first link called head.
3. 3
Types of Linked List
• Single Linked List − Item navigation is forward
only.
• Doubly Linked List − Items can be navigated
forward and backward.
• Circular Linked List − Last item contains link of
the first element as next and the first element
has a link to the last element as previous.
4. 4
Operations of Linked List
• Insert − Add an element into list.
• Delete − Remove an element of the list.
• Search − Searches an element using the given
key.
• Sort - Sort List elements
• Merge – Join 2 list elements
• Display − Displays the complete list.
11. 11
Circular Linked List
Singly Linked List
• Pointer of the last node points to the first node
Doubly linked list
• The next pointer of the last node points to the first node and the previous
pointer of the first node points to the last node making the circular in both
directions.
12. 12
Circular Linked List
Singly Linked List
struct node
{
int data;
struct node *next;
};
typedef struct node *list;
typedef struct node *position;
Doubly Linked List
struct node
{
int data;
struct node *flink;
struct node *blink;
};
struct node *head;
13. 13
Insertion
1. Insertion at the beginning of the list
2. Insertion at the end of the list
3. Insertion in between the nodes
14. 14
Insertion at the beginning of the list
struct Node *addBegin(struct Node *last, int data)
{
// Creating a node dynamically.
struct Node *temp = (struct Node *)malloc(sizeof(struct Node));
// Assigning the data.
temp -> data = data;
// Adjusting the links.
head=temp;
temp -> next = last -> next;
last -> next = temp;
return last;
}
15. 15
Insertion at the end of the list
struct Node *addEnd(struct Node *last, int data)
{
// Creating a node dynamically.
struct Node *temp = (struct Node *)malloc( sizeof(struct Node));
// Assigning the data.
temp -> data = data;
// Adjusting the links.
temp -> next = last -> next;
last -> next = temp;
last = temp;
return last;
}