Linked List
Linked List
LINKED LIST
This is a special kind of list where data items are
linked to one another.
Each data item has address of its next element.
Data Next
Node
OPERATIONS ON LINKED LIST
Following basic operations are performed on
linked list:
Create a new linked list.
Head Node
100
Head node
100
pre data next
NULL 2 200 100 4 300 200 6 NULL
200 300
100
3) Circular Linked List:
Each node has two parts data and next.
Head Node
100
struct node {
int data;
struct node *next;
};
The data part data contains an integer value and the next pointer
stores the address of the next node (if exists, otherwise NULL).
HOW TO CREATE A LINKED LIST?
2. Declare a pointer to the node type variable to store the link of
the first node of the linked list. Say,
Note: You can also declare variable of node type along with the node
structure definition.
3. Input the number of nodes to create from the user, and store it
in some variable say n.
11. If memory got allocated successfully, then read data from the
user and assign to the data section of the new node. Say
newNode->data = data;
12. Make sure the new node points to NULL.
13. Now link the previous node with the newly created node i.e.
temp->next = newNode;
HOW TO CREATE A LINKED LIST?
14. Make the current node as the previous node using
temp = temp->next;
15. Repeat steps 10-14 for the remaining (n – 2) other nodes.
int main()
{
int n;
printf("Enter the total number of nodes: ");
scanf("%d", &n);
createList(n);
return 0;
}
Here data part num contains an integer value and next pointer stores
the address of the next node.
INSERTION AT THE BEGIN
Head Node
100
100
9 NULL
Head Node
100
100 500
100
Head Node
100
Head Node
200
4 300 6 NULL
200 300
DELETE FROM END
Head Node
100
Head Node
100
2 200 4 NULL
100 200
DELETE FROM SPECIFIC POSITION
Head Node
100
Head Node
100