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

Program 8

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

Program 8

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

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.
Create a DLL of N Employees Data by using end insertion.
Display the status of DLL and count the number of nodes in it
Perform Insertion and Deletion at End of DLL
Perform Insertion and Deletion at Front of DLL
Demonstrate how this DLL can be used as Double Ended Queue
Exit

#include<stdio.h>
struct node
{
char ssn[20],name[20],dept[20],desi[20],phno[20];
float salary;
struct node *next;
struct node *prev;
};
typedef struct node *NODE;
NODE first=NULL;
NODE read()
{
NODE temp;
char ssn[20],name[20],dept[20],desi[20],phno[20];
float sal;
printf("Enter the employee ssn,name,dept,designation,sal and phno:\n");
scanf("%s%s%s%s%f%s",ssn,name,dept,desi,&sal,phno);
temp=(NODE)malloc(sizeof(struct node));
strcpy(temp->ssn,ssn);
strcpy(temp->name,name);
strcpy(temp->dept,dept);
strcpy(temp->desi,desi);
temp->salary=sal;
strcpy(temp->phno,phno);
return temp;
}
void addfront()
{
NODE nw;
nw=read();
if(first==NULL)
{
first=nw;
first->prev=first->next=NULL;
}
else
{
nw->next=first;
first->prev=nw;
nw->prev=NULL;
first=nw;
}
}
void addend()
{
NODE nw,p;
nw=read();
if(first==NULL)
{
first=nw;
first->prev=first->next=NULL;
}
p=first;
while(p->next!=NULL)
p=p->next;
p->next=nw;
nw->prev=p;
nw->next=NULL;
}
void delfront()
{
NODE temp;
temp=first;
if(temp->next==NULL&&temp->prev==NULL)
first=NULL;
else
{
first=temp->next;
first->prev=NULL;
}
printf("Employee information deleted with ssn %s:",temp->ssn);
free(temp);
}
void delend()
{
NODE temp,p;
temp=first;
if(temp->next==NULL&&temp->prev==NULL)
first=NULL;
else
{
while(temp->next!=NULL)
temp=temp->next;
p=temp->prev;
p->next=NULL;
}
printf("Employee information deleted with ssn %s:",temp->ssn);
free(temp);
}
void display()
{
NODE temp;
temp=first;
printf("\nSSN\tNAME\tDEPT\tDESI\tSALARY\tPHNO\n");
while(temp!=NULL)
{
printf("%s\t%s\t%s\t%s\t%5.2f\t%s\t\n",temp->ssn,temp->name,temp->dept,temp->desi,temp-
>salary,temp->phno);
temp=temp->next;
}
}
void main()
{
int choice;
clrscr();
printf("\nDoubly Linked List is demonstrated as Double Ended Queue\n");
while(1)
{
printf("\n 1:CREATE(ADDEND)\n 2:DISPLAY\n 3:DELETION AT END\n 4:INSETION AT
FRONT\n 5:DELETION AT FRONT\n 6:EXIT\n");
printf("enter the choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:addend();
break;
case 2:if(first==NULL)
printf("List is Empty\n");
else
display();
break;
case 3:if(first==NULL)
printf("List is Empty\n");
else
delend();
break;
case 4:addfront();
break;
case 5:if(first==NULL)
printf("List is Empty\n");
else
delfront();
break;
case 6:exit(0);
default:printf("invalid choice\n");
break;
}
}
}

You might also like