8 DLL
8 DLL
8. Develop a menu driven Program in C for the following operations on Doubly Linked
List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal,
PhNo
a. Create a DLL of N Employees Data by using end insertion.
b. Display the status of DLL and count the number of nodes in it
c. Perform Insertion and Deletion at End of DLL
d. Perform Insertion and Deletion at Front of DLL
e. Demonstrate how this DLL can be used as Double Ended Queue.
f. Exit
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int SSN;
char Name[30],Dept[4],Designation[30],PhNo[11];
int Salary;
struct node *plink;
struct node *nlink;
};
typedef struct node* NODEPTR;
NODEPTR GetNode(void);
void FreeNode(NODEPTR);
NODEPTR InsRear(NODEPTR);
NODEPTR DelFront(NODEPTR);
NODEPTR InsFront(NODEPTR);
NODEPTR DelRear(NODEPTR);
void Display(NODEPTR);
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.
Department of Computer Science & Engineering, GMIT, Davangere.
int main()
{
NODEPTR first = NULL;
int Choice,Num,i;
printf("\n Enter the number of Employees N : ");
scanf("%d",&Num);
for(i=0;i<Num;i++)
{
printf("\n Enter Data for Node %d :\n", i+1);
first = InsRear(first);
}
for(;;)
{
printf("\n DLL OPERATIONS\n");
printf("====================");
printf("\n 1.Insert Rear\n 2.Delete Front\n 3.Insert
Front\n 4.Delete Rear\n 5.Display\n 6.Exit\n");
printf("\n Enter your choice\n");
scanf("%d",&Choice);
switch(Choice)
{
case 1: first = InsRear(first);
break;
case 2: first = DelFront(first);
break;
case 3: first = InsFront(first);
break;
case 4: first = DelRear(first);
break;
case 5: Display(first);
break;
case 6: exit(0);
}
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.
Department of Computer Science & Engineering, GMIT, Davangere.
}
return 0;
}
NODEPTR GetNode()
{
NODEPTR newborn;
newborn = (NODEPTR)malloc(sizeof(struct node));
if(newborn == NULL)
{
printf("\n Memory Overflow");
exit(0);
}
printf("\n Enter SSN : ");
scanf("%d",&newborn->SSN);
printf("\nEnter name : ");
scanf("%s",newborn->Name);
printf("\n Enter Department : ");
scanf("%s", newborn->Dept);
printf("\n Enter Designation : ");
scanf("%s", newborn->Designation);
printf("\n Enter Salary : ");
scanf("%d",&newborn->Salary);
printf("\n Enter Phone no : ");
scanf("%s",newborn->PhNo);
return newborn;
}
void FreeNode(NODEPTR x)
{
free(x);
}
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.
Department of Computer Science & Engineering, GMIT, Davangere.
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.
Department of Computer Science & Engineering, GMIT, Davangere.
}
cur = first;
if(cur->nlink == NULL)
{
printf("\n Node deleted for %s\n",cur->Name);
FreeNode(cur);
return NULL;
}
while(cur->nlink != NULL)
{
cur = cur->nlink;
}
prev = cur->plink;
prev->nlink = NULL;
printf("\n Node deleted for %s\n",cur->Name);
FreeNode(cur);
return first;
}
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.
Department of Computer Science & Engineering, GMIT, Davangere.
temp = first;
first = first->nlink;
first->plink = NULL;
printf("\n Node deleted for %s\n",temp->Name);
FreeNode(temp);
return first;
}
DSA Lab (BCSL305) Programs: Prepared by Mr. Shankar Shastri, Assistant Professor.