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>
// Employee structure
struct employee {
int SSN;
char name[50];
char dept[50];
char designation[50];
float sal;
char phNo[15];
struct employee *prev;
struct employee *next;
};
typedef struct employee *NODE;
// Function to create a new node
NODE getnode() {
NODE temp = (NODE)malloc(sizeof(struct employee));
if (!temp) {
printf("Memory allocation failed\n");
exit(1);
return temp;
// Function to create DLL with N Employees by end insertion
NODE create_list(int N) {
NODE first = NULL, temp, cur;
int i;
for (i = 0; i < N; i++) {
temp = getnode();
printf("\nEnter employee details (SSN, Name, Dept, Designation, Salary, Phone
Number):\n");
printf("SSN: ");
scanf("%d", &temp->SSN);
getchar(); // To consume the newline character left by scanf
printf("Name: ");
fgets(temp->name, 50, stdin);
temp->name[strcspn(temp->name, "\n")] = 0; // Remove newline character
printf("Department: ");
fgets(temp->dept, 50, stdin);
temp->dept[strcspn(temp->dept, "\n")] = 0; // Remove newline character
printf("Designation: ");
fgets(temp->designation, 50, stdin);
temp->designation[strcspn(temp->designation, "\n")] = 0; // Remove newline
character
printf("Salary: ");
scanf("%f", &temp->sal);
getchar(); // To consume the newline character
printf("Phone Number: ");
fgets(temp->phNo, 15, stdin);
temp->phNo[strcspn(temp->phNo, "\n")] = 0; // Remove newline character
temp->next = NULL;
if (first == NULL) {
temp->prev = NULL;
first = temp;
} else {
cur = first;
while (cur->next != NULL) {
cur = cur->next;
}
cur->next = temp;
temp->prev = cur;
return first;
// Function to display the DLL and count the number of nodes
void display(NODE first) {
if (first == NULL) {
printf("\nList is empty\n");
return;
NODE cur = first;
int count = 0;
printf("\nEmployee Data (Forward):\n");
while (cur != NULL) {
printf("SSN: %d, Name: %s, Dept: %s, Designation: %s, Salary: %.2f, Phone:
%s\n",
cur->SSN, cur->name, cur->dept, cur->designation, cur->sal, cur->phNo);
count++;
cur = cur->next;
}
printf("\nTotal Employees: %d\n", count);
// Function to insert at the end of the DLL
NODE insert_end(NODE first) {
NODE temp = getnode();
NODE cur;
printf("\nEnter new employee details (SSN, Name, Dept, Designation, Salary, Phone
Number):\n");
printf("SSN: ");
scanf("%d", &temp->SSN);
getchar(); // To consume the newline character
printf("Name: ");
fgets(temp->name, 50, stdin);
temp->name[strcspn(temp->name, "\n")] = 0; // Remove newline character
printf("Department: ");
fgets(temp->dept, 50, stdin);
temp->dept[strcspn(temp->dept, "\n")] = 0; // Remove newline character
printf("Designation: ");
fgets(temp->designation, 50, stdin);
temp->designation[strcspn(temp->designation, "\n")] = 0; // Remove newline
character
printf("Salary: ");
scanf("%f", &temp->sal);
getchar(); // To consume the newline character
printf("Phone Number: ");
fgets(temp->phNo, 15, stdin);
temp->phNo[strcspn(temp->phNo, "\n")] = 0; // Remove newline character
temp->next = NULL;
if (first == NULL) {
temp->prev = NULL;
return temp;
cur = first;
while (cur->next != NULL) {
cur = cur->next;
cur->next = temp;
temp->prev = cur;
return first;
// Function to delete from the end of the DLL
NODE delete_end(NODE first) {
if (first == NULL) {
printf("\nList is empty, cannot delete\n");
return NULL;
NODE cur = first;
while (cur->next != NULL) {
cur = cur->next;
if (cur->prev != NULL) {
cur->prev->next = NULL;
} else {
first = NULL;
printf("\nDeleted Employee Data:\nSSN: %d, Name: %s, Dept: %s, Designation: %s,
Salary: %.2f, Phone: %s\n",
cur->SSN, cur->name, cur->dept, cur->designation, cur->sal, cur->phNo);
free(cur);
return first;
}
// Function to insert at the front of the DLL
NODE insert_front(NODE first) {
NODE temp = getnode();
printf("\nEnter new employee details (SSN, Name, Dept, Designation, Salary, Phone
Number):\n");
printf("SSN: ");
scanf("%d", &temp->SSN);
getchar(); // To consume the newline character
printf("Name: ");
fgets(temp->name, 50, stdin);
temp->name[strcspn(temp->name, "\n")] = 0; // Remove newline character
printf("Department: ");
fgets(temp->dept, 50, stdin);
temp->dept[strcspn(temp->dept, "\n")] = 0; // Remove newline character
printf("Designation: ");
fgets(temp->designation, 50, stdin);
temp->designation[strcspn(temp->designation, "\n")] = 0; // Remove newline
character
printf("Salary: ");
scanf("%f", &temp->sal);
getchar(); // To consume the newline character
printf("Phone Number: ");
fgets(temp->phNo, 15, stdin);
temp->phNo[strcspn(temp->phNo, "\n")] = 0; // Remove newline character
temp->prev = NULL;
temp->next = first;
if (first != NULL) {
first->prev = temp;
return temp;
// Function to delete from the front of the DLL
NODE delete_front(NODE first) {
if (first == NULL) {
printf("\nList is empty, cannot delete\n");
return NULL;
NODE temp = first;
first = first->next;
if (first != NULL) {
first->prev = NULL;
}
printf("\nDeleted Employee Data:\nSSN: %d, Name: %s, Dept: %s, Designation: %s,
Salary: %.2f, Phone: %s\n",
temp->SSN, temp->name, temp->dept, temp->designation, temp->sal, temp-
>phNo);
free(temp);
return first;
// Main function
int main() {
NODE first = NULL;
int choice, N;
while (1) {
printf("\nMenu:\n");
printf("1. Create DLL of N Employees\n");
printf("2. Display DLL and count nodes\n");
printf("3. Insert at End\n");
printf("4. Delete from End\n");
printf("5. Insert at Front\n");
printf("6. Delete from Front\n");
printf("7. Demonstrate Double Ended Queue\n");
printf("8. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nEnter the number of employees: ");
scanf("%d", &N);
first = create_list(N);
break;
case 2:
display(first);
break;
case 3:
first = insert_end(first);
break;
case 4:
first = delete_end(first);
break;
case 5:
first = insert_front(first);
break;
case 6:
first = delete_front(first);
break;
case 7:
// Demonstrate Double Ended Queue (Just an example)
printf("\nUsing DLL as Double Ended Queue\n");
first = insert_end