0% found this document useful (0 votes)
8 views3 pages

C Program for Employee DLL Operations

The document outlines a C program for managing a Doubly Linked List (DLL) of employee data, including fields such as SSN, Name, Dept, Designation, Salary, and Phone Number. It provides functionalities for creating the DLL, displaying employee details, inserting and deleting nodes at both ends, and demonstrates the DLL's use as a double-ended queue. The program includes a menu-driven interface for user interaction with these operations.

Uploaded by

drawingworld9686
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

C Program for Employee DLL Operations

The document outlines a C program for managing a Doubly Linked List (DLL) of employee data, including fields such as SSN, Name, Dept, Designation, Salary, and Phone Number. It provides functionalities for creating the DLL, displaying employee details, inserting and deleting nodes at both ends, and demonstrates the DLL's use as a double-ended queue. The program includes a menu-driven interface for user interaction with these operations.

Uploaded by

drawingworld9686
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 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 Enode
{
char ssn[15];
char name[20];
char dept[5];
char designation[10];
long int salary;
long long int phno;
struct Enode *left;
struct Enode *right;
}*head=NULL;
struct Enode *tail,*temp1,*temp2;
int count=0;

void create(char s[15],char n[20],char dpt[5],char des[10],long int


sal,long long int p)
{
if(head==NULL)
{
head=(struct Enode *)malloc(1*sizeof(struct Enode));
strcpy(head->ssn,s);
strcpy(head->name,n);
strcpy(head->dept,dpt);
strcpy(head->designation,des);
head->salary=sal;
head->phno=p;
head->left=NULL;
head->right=NULL;
tail=head;
count++;
}
else
{
temp1=(struct Enode *)malloc(1*sizeof(struct Enode));
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p;
tail->right=temp1;
temp1->right=NULL;
temp1->left=tail;
tail=temp1;
count++;
}
}

void display()
{
temp1=head;
printf("Employee Details \n");
while(temp1!=NULL)
{
printf(" \n");
printf("%s\n%s\n%s\n%s\n%ld\n%lld\n",temp1->ssn,temp1->name,temp1-
>dept,temp1->designation,temp1->salary,temp1->phno);
printf(" ");
temp1=temp1->right;
}
printf(“Number of nodes are %d\n”, count);
}

void ins_beg(char s[15],char n[20],char dpt[5],char des[10],long int


sal,long long int p)
{
temp1=(struct Enode * )malloc(1*sizeof(struct Enode));
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p;
temp1->right=head;
head->left=temp1;
head=temp1;
temp1->left=NULL;
count++;
}

void ins_end(char s[15],char n[20],char dpt[5],char des[10],long int


sal,long long int p)
{
temp1=(struct Enode *)malloc(1*sizeof(struct Enode));
strcpy(temp1->ssn,s);
strcpy(temp1->name,n);
strcpy(temp1->dept,dpt);
strcpy(temp1->designation,des);
temp1->salary=sal;
temp1->phno=p;
tail->right=temp1;
temp1->left=tail;
temp1->right=NULL;
tail=temp1;
count++;
}

void del_beg()
{
temp1=head->right;
free(head);
head=temp1;
head->left=NULL;
count--;
}

void del_end()
{
temp1=tail->left;
free(tail);
tail=temp1;
tail->right=NULL;
count--;
}

void main()
{
int choice;
char s[15],n[20],dpt[5],des[10];
long int sal;
long long int p;
printf("[Link]\[Link]\[Link] at beginning\[Link] at End\
[Link] at beginning\[Link] at End\[Link]\n");
while(1)
{
printf("\nEnter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Enter the required data(Emp
no,Name,Dept,Desig,sal,phone\n");
scanf("%s%s%s%s%ld%lld",s,n,dpt,des,&sal,&p);
create(s,n,dpt,des,sal,p);
break;
case 2:display();
break;
case 3:printf("Enter the required data (Emp
no,Name,Dept,Desig,sal,phone\n");
scanf("%s%s%s%s%ld%lld",s,n,dpt,des,&sal,&p);
ins_beg(s,n,dpt,des,sal,p);
break;
case 4:printf("Enter the required data(Emp
no,Name,Dept,Desig,sal,phone\n");
scanf("%s%s%s%s%ld%lld",s,n,dpt,des,&sal,&p);
ins_end(s,n,dpt,des,sal,p);
break;
case 5:del_beg();
break;
case 6:del_end();
break;
case 7:exit(0);
}
}
}

You might also like