0% found this document useful (0 votes)
3 views

DSA Program 8 (1)

The document outlines a C program for managing a Doubly Linked List (DLL) of employee data, including operations such as creating the list, displaying the list and its count, and performing insertions and deletions at both ends. It provides a menu-driven interface for users to interact with the DLL. The program includes functions for reading employee details and managing the list structure effectively.

Uploaded by

sagarsriram535
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DSA Program 8 (1)

The document outlines a C program for managing a Doubly Linked List (DLL) of employee data, including operations such as creating the list, displaying the list and its count, and performing insertions and deletions at both ends. It provides a menu-driven interface for users to interact with the DLL. The program includes functions for reading employee details and managing the list structure effectively.

Uploaded by

sagarsriram535
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Laboratory Program – 08

Design, Develop and Implement 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
C Program:

#include<stdio.h>
#include<stdlib.h>
#define NULL 0

struct node
{
char ssn[10],name[20],dept[10],desg[10],phno[15];
int sal;
struct node *rlink;
struct node *llink;
};

typedef struct node *nodepointer;


nodepointer temp,first=NULL,end=NULL;

nodepointer getnode()
{
nodepointer x;
x=(nodepointer)malloc(sizeof(struct node));
return x;
}

void read()
{
temp=getnode();
temp->llink=NULL;
temp->rlink=NULL;
printf("Enter the ssn\n");
gets(temp->ssn);
printf("Enter the name\n");
gets(temp->name);
printf("enter the department\n");
gets(temp->dept);
printf("Enter the designation\n");
gets(temp->desg);
printf("Enter the phone number\n");
gets(temp->phno);
printf("Enter the salary\n");
scanf("%d%*c",&temp->sal);
}
void createdll()
{
int n,i;
printf("Enter the number of employees\n");
scanf("%d%*c",&n);
for(i=1;i<=n;i++)
{
printf("Enter the details of employee %d\n",i);
read();
if(first==NULL)
{
first=temp;
end=temp;
}
else
{
end->rlink=temp;
temp->llink=end;
end=temp;
}
}
}

void displaycount()
{
int count=0;
nodepointer temp1=first;
if(first==NULL)
printf("DLL is empty and count is %d\n",count);
else
{

printf("\n_________________________________________________________\n")
;
printf("\nssn\tname\t\tdept\tdesg\tphno\t\tsal\n");
printf("\n_________________________________________________________\n")
;
while(temp1!=NULL)
{
printf("%s\t%s\t%s\t%s\t%s\t%d\n",temp1->ssn,temp1->
name,temp1->dept,temp1->desg,temp1->phno,temp1->sal);
count++;
temp1=temp1->rlink
}

printf("\n_________________________________________________________\n")
;
printf("employee count is %d\n",count);
}
}
void insertend()
{
temp=getnode();
printf("Enter the details of new employee\n");
read();
if(first==NULL)
{
first=temp;
end=temp;
}
else
{
end->rlink=temp;
temp->llink=end;
end=temp;
}

void deleteend()
{
nodepointer temp1=end;
if(temp1==NULL)
{
printf("DLL is empty\n");
}
else if(first==end)
{
printf("The deleted element is with ssn %s\n",temp1->ssn);
first=NULL;
end=NULL;
free(temp1);
}
else
{
printf("The deleted element is with ssn %s\n",temp1->ssn);
end=end->llink;
end->rlink=NULL;
free(temp1);
}
}

void insertfront()
{
printf("Enter the details of employee\n");
read();
if(first==NULL)
{
first=temp;
end=temp;
}
else
{
temp->rlink=first;
first->llink=temp;
first=temp;
}
}
void deletefront()
{
nodepointer temp1=first;
if(first==NULL)
printf("DLL is empty\n");
else if(first==end)
{
printf("The deleted element is with ssn %s\n",temp1->ssn);
first=NULL;
end=NULL;
free(temp1);
}
else
{
printf("The deleted element is with the ssn %s\n",temp1->ssn);
first=first->rlink;
first->llink=NULL;
free(temp1);

}
}

int main()
{
int ch;
while(1)
{
printf("Double Linked List\n");
printf("MENU\n1.Create\t2.Display and Count\t3.Insert End\t
4.Delete End\t5.Insert Front\t6.Delete Front\t7.Exit\n");
printf("Enter your choice\n");
scanf("%d%*c",&ch);
switch(ch)
{
case 1: createdll();
break;
case 2: displaycount();
break;
case 3: insertend();
break;
case 4: deleteend();
break;
case 5: insertfront();
break;
case 6: deletefront();
break;
case 7: exit(0);
default:printf("Enter the valid choice\n");
}
}
return 0;
}

You might also like