In this chapter we will discuss about some points that's needs to know before using of linked list and you will know about some operations that can be performed on linked list.
Single Linked List
Before going further, now let us see how we can represent a node of a single linked list in C language.
Node means memory of block that contains collection of data item and at least one pointer that points the next or previous node(memory block).
Let us see some examples of nodes-
struct node{ int value; struct node *link; }; |
|
||||
struct node{ char name[10]; int id_no; float salary; struct node *link; }; |
|
||||
struct node{ struct student stu; struct node *link; }; |
|
In array we could perform all the operations using the array name and index. In case of linked list, we will perform all the operations with the help of pointer start because it is the only source through which we can access our linked list.
The list will be considered empty if the pointer start contains NULL value. So our first job is to declare the pointer start and initialize it to NULL.
This can be done as-
start = NULL;
These two lines are compulsory to write in a program if you want to create a linked list because it is a good practice to write.
Here we assigned NULL in start pointer because by the help of if function we can easily find out that the pointer start is pointing any memory block(node) or not.
if start shows NULL value that means it is not pointing any node. And, now we can creat a list to assign its address in start pointer.
We will implement these codes in program and discuss some following operations on a single linked list one by one.
- Traversal of a linked list
- Searching an element
- Insertion of an element
- Deletion of an element
- Creation of a linked list
- Reversal of a linked list