Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Double LList

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

8.

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

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>
struct node
{
char ssn[20],name[20],dept[20],desg[20];
int sal;
long int phno;
struct node *llink;
struct node *rlink;
};
typedef struct node *NODE;
NODE first=NULL;
NODE nn;
int count=0;
void allocate()
{
nn=(NODE)malloc(sizeof(struct node));
printf("enter ssn\n");
scanf("%s",nn->ssn);
printf("enter name\n");
scanf("%s",nn->name);
printf("enter dept\n");
scanf("%s",nn->dept);
printf("enter desg\n");
scanf("%s",nn->desg);
printf("enter salary\n");
scanf("%d",&nn->sal);
printf("enter phone no\n");
scanf("%ld",&nn->phno);
nn->llink=NULL;
nn->rlink=NULL;
}
void insert_rear()
{
NODE cur;
allocate();
count++;
if(first==NULL)
{
first=nn;
return;
}
cur=first;
while(cur->rlink!=NULL)
{
cur=cur->rlink;
}
cur->rlink=nn;
nn->llink=cur;
}
void insert_front()
{
allocate();
count++;
if(first==NULL)
{
first=nn;
return;
}
nn->rlink=first;
first->llink=nn;
first=nn;
}
void delete_front()
{
NODE temp;
if(first==NULL)
{
printf("list empty,cannot delete\n");
return;
}
count--;
temp=first;
printf("Deleted employee is %s\t%s\t%s\t%s\t%d\t%ld\n",temp-
>ssn,temp->name,temp->dept,temp->desg,temp->sal,temp->phno);
first=first->rlink;
first->llink=NULL;
free(temp);
}
void delete_rear()
{
NODE cur,prev;
if(first==NULL)
{
printf("list empty,cannot delete\n");
return;
}
count--;
cur=first;
while(cur->rlink!=NULL)
{
prev=cur;
cur=cur->rlink;
}
printf("Deleted record is %s\t%s\t%s\t%s\t%d\t%ld\n",cur-
>ssn,cur->name,cur->dept,cur->desg,cur->sal,cur->phno);
prev->rlink=NULL;
free(cur);
}
void display()
{
NODE cur;
if(first==NULL)
{
printf("list empty\n");
return;
}
cur=first;
while(cur!=NULL)
{
printf("%s\t%s\t%s\t%s\t%d\t%ld\n",cur->ssn,cur->name,cur-
>dept,cur->desg,cur->sal,cur->phno);
cur=cur->rlink;
}
printf("Number of employess is %d\n",count);
}
void main()
{
int choice,n,i;
clrscr();
for(;;)
{
printf("1:Create Employee list 2:Display 3:Insert front
4:insert rear 5:Delete front 6:Delete rear 7:exit\n");
printf("enter choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("enter numbe of employess\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
insert_rear();
}
break;
case 2: display();
break;
case 3: insert_front();
break;
case 4:insert_rear();
break;
case 5: delete_front();
break;
case 6: delete_rear();
break;
case 7: exit(0);
break;
}
}
}

You might also like