IMPLEMENTATION OF DOUBLY LINKED LIST AND ITS OPERATIONS
TO LEARN C PROGRAMMING FOLLOW THIS YOUTUBE CHANNEL : Code with u - YouTube
AIM:
To implement doubly linked list and performing insert, search, view and delete operations.
ALGORITHM:
1. CREATION:
a. Creating a node
b. Reading details for a node from user
c. Connect the node with the list
2. INSERTION:
a. Get the node using struct node(), and read the details of the node using new node()
b. Check whether the list is empty or not
c. FIRST- The forward link field of the new node is made to point the data field of the first node in the list by assigning of the first node.
d. The backward link field of the first node is made to point the data field of the first node in the list by assigning of the new node.
e. Assigning the new node as the head pointer
f. LAST – the forward link field of the last node is made to point the new node by assigning the address of the new node.
g. The backward link field of the new node is made to point the last node in the list by assigning the address of the new node.
h. The forward link field of the new node is set to NULL.
I. MIDDLE- the forward link field of the new node is made to point the next node in the list by assigning its address
j. The backward link field of the next node is made to point the new node, by assigning the address of the preceding node
k. The forward link field of the preceding node is made to point the new node, by assigning the address of the new node.
3. DISPLAY
a. Get the contents from the list
b. If the list is empty print it is empty.
c. If the list is not empty print the entire list.
4. FIND
a. It finds the address of the given element and returns the address of the particular element.
b. Returns null if the element is not found.
5. DELETION
a. Check whether the list is empty or not.
b. FIRST – set the head pointer of the second node in the list
c. Set the backward link filed of the head in the list to NULL
d. Release the memory for the deleted node
e. LAST- The link field of the previous node
f. The forward link field of the previous node is set to NULL
g. Release the memory for the deleted node
h. MIDDLE- The forward link field of the previous node is made to point the previous node, by assigning its address
I. Release the memory for the deleted node.
NOTE :
In the below content incase of some error problem the program was slightly modified, so to remodel it the following steps should be taken
1.)In "d node" remove the space between "d" and "node".
2.)In "print f" remove the space between "print" and "f".
3.)In "scan f" remove the space between "scan" and "f".
PROGRAM :
#include<std io. h>
d node * create()
{
int x, n, I;
d node *head=NULL;
d node *p;
print f("\n Enter no of data : ");
scan f("%d", &n);
for(I=0;I<n; I++)
{
print f("\n Next Data : ");
scan f("%d", &x);
if(head==NULL)//insert the first node
{
head=p=(d node*)malloc(size of(d node));
loc=search(head, x);
if(loc==-1)
print f("\n Element not found ");
else
print f("\n Found at location :%d ",loc+1);
break;
}
}
while(op<6);
}
OUTPUT :
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 1
Enter no of data : 3
Next Data : 3
Next Data : 4
Next Data : 5
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 2
Data stored in the Doubly linked list : 3 4 5
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 4
Enter the location :2
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 2
Data stored in the Doubly linked list : 3 5
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 3
Enter the location :55
Enter the data :2
Overflow ****
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 5
Enter element to be searched : 3
Found at location :1
1)Create
2)Print
3)Insert
4)Delete
5)Search
6)Quit
Enter your Choice : 6
RESULT:
Thus the program for doubly linked List and its operations was implemented and it’s executed successfully.