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, Designation, Department, Salary, Phone no.

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, Designation, Department, Salary, Phone no.

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, Designation, Department, Salary, Phone no.

(i) Create a DLL of n employee data by using end insertion
(ii) Display the status of DLL and count the number of nodes in it
(iii) Perform insertion and deletion at the front of DLL
(iv) Perform insertion and deletion at the end of DLL
(v) Demonstrate how this DLL can be used as double ended queue
(vi) Exit

Program:-

#include<stdio.h>
#include<alloc.h>
#include<conio.h>
struct dll
{
int ssn;
char name[10];
char dept[10];
char desig[10];
int sal;
int phno;
struct dll *prev,*next;
};
typedef struct dll node;
node *start = NULL;
node *getnode()
{
node *n;
n=(node*)malloc(sizeof(node));
printf("Enter the SSN\n");
scanf("%d",&n->ssn);
printf("Enter the NAME\n");
scanf("%s",n->name);
printf("Enter the DEPARTMENT\n");
scanf("%s",n->dept);
printf("Enter the DESIGNATION\n");
scanf("%s",n->desig);
printf("Enter the SALARY\n");
scanf("%d",&n->sal);
printf("Enter the PHONE NUM\n");
scanf("%d",&n->phno);
n->prev=n->next=NULL;
return n;
}
void ins_beg()
{
node *n;
n=getnode();
if(start == NULL)
{
start = n;
return;
}
n->next=start;
start->prev=n;
start=n;
}
void ins_end()
{
node *temp=start,*n;
n = getnode();
if(start == NULL)
{
start = n;
return;
}
while(temp->next!=NULL)
temp=temp->next;
temp->next = n;
n->prev = temp;
}
void del_beg()
{
node *temp=start;
if(start == NULL)
{
printf("deletion not possible");
return;
}
printf("The record %d is deleted ",temp->ssn);
start = temp->next;
start -> prev = NULL;
free(temp);
return;
}
void del_end()
{
node *temp=start,*prev;
if(start == NULL)
{
printf("list empty");
return;
}
while(temp->next!=NULL)
{
prev=temp;
temp=temp->next;
}
prev->next = NULL;
printf("The record %d is deleted ",temp->ssn);
free(temp);
}
void display()
{
node *temp=start;
int cnt=0;
if(start == NULL)
{
printf("The DLL is empty");
return;
}
printf("The contents of DLL are \n");
while(temp!=NULL)
{
printf("%d %s %s %s %d\n",temp->ssn, temp->name, temp->desig, temp->sal,temp->phno);
temp=temp->next;
cnt++;
}
printf("num of nodes in the DLL is %d ", cnt);
}
int main()
{
int choice,n,i;
clrscr();
while(1)
{
printf("\n 1.Create n students data using Insertion at End \n 2.Insert front \n3. Insert end \n ");
printf("4.Delete front\n 5.Delete end \n 6. Display \n 7. Exit\n");
printf("Enter choice \n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter how many records?");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter record %d",i);
ins_end();
}
break;
case 2:ins_beg();break;
case 3:ins_end();break;
case 4:del_beg();break;
case 5:del_end();break;
case 6:display();break;
case 7:printf("Exiting ... \n");exit(1);
break;
default : printf("Invalid choice\n");
break;
}
}
}

Click to rate this post!
[Total: 0 Average: 0]

We will be happy to hear your thoughts

Leave a reply

EducationTrick
Logo
Enable registration in settings - general