PGM 8
PGM 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.
f. Exit
#include <stdio.h>
#include <stdlib.h>
struct Employee {
char SSN[15];
char Name[30];
char Dept[20];
char Designation[30];
float Sal;
};
scanf("%s", newNode->SSN);
scanf("%s", newNode->Name);
printf("Enter Dept: ");
scanf("%s", newNode->Dept);
scanf("%s", newNode->Designation);
scanf("%f", &newNode->Sal);
scanf("%lld", &newNode->PhNo);
newNode->next = NULL;
newNode->prev = NULL;
return newNode;
if (*head == NULL) {
} else {
newNode->prev = *tail;
(*tail)->next = newNode;
*tail = newNode;
// Function to display the status of the doubly linked list and count nodes
printf("List is empty.\n");
return;
int count = 0;
printf("SSN: %s, Name: %s, Dept: %s, Designation: %s, Salary: %.2f, Phone: %lld\n",
current = current->next;
count++;
if (*head == NULL) {
} else {
newNode->next = *head;
(*head)->prev = newNode;
*head = newNode;
}
printf("Node inserted at the front successfully.\n");
if (*head == NULL) {
return;
if ((*head)->next == NULL) {
free(*head);
return;
*tail = (*tail)->prev;
(*tail)->next = NULL;
free(temp);
if (*head == NULL) {
return;
}
if ((*head)->next == NULL) {
free(*head);
return;
*head = (*head)->next;
(*head)->prev = NULL;
free(temp);
next = current->next;
free(current);
current = next;
}
int main() {
int choice;
do {
printf("\nMenu:\n");
printf("7. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insertEnd(&head, &tail);
break;
case 2:
displayStatus(head);
break;
case 3:
insertFront(&head, &tail);
break;
case 4:
deleteEnd(&head, &tail);
break;
case 5:
deleteFront(&head, &tail);
break;
case 6:
break;
case 7:
freeList(&head, &tail);
break;
default:
return 0;