prg8DSA
prg8DSA
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>
printf("\nEmployees in DLL:\n");
struct Employee* temp = head;
while (temp != NULL) {
printf("SSN: %s, Name: %s, Dept: %s, Designation: %s, Salary: %.2f, Phone:
%s\n",
temp->SSN, temp->Name, temp->Dept, temp->Designation, temp->Sal,
temp->PhNo);
temp = temp->next;
}
}
// Main function
int main() {
struct Employee* head = NULL; // Initialize the DLL as empty
int choice;
char ssn[15], name[50], dept[20], designation[20], phno[15];
float sal;
while (1) {
printf("\nMenu:\n");
printf("1. Insert at end\n");
printf("2. Insert at front\n");
printf("3. Delete at front\n");
printf("4. Delete at end\n");
printf("5. Display list\n");
printf("6. Count nodes\n");
printf("7. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter SSN: ");
scanf("%s", ssn);
printf("Enter Name: ");
scanf("%s", name);
printf("Enter Dept: ");
scanf("%s", dept);
printf("Enter Designation: ");
scanf("%s", designation);
printf("Enter Salary: ");
scanf("%f", &sal);
printf("Enter Phone: ");
scanf("%s", phno);
insertAtEnd(&head, createEmployee(ssn, name, dept, designation,
sal, phno));
break;
case 2:
printf("Enter SSN: ");
scanf("%s", ssn);
printf("Enter Name: ");
scanf("%s", name);
printf("Enter Dept: ");
scanf("%s", dept);
printf("Enter Designation: ");
scanf("%s", designation);
printf("Enter Salary: ");
scanf("%f", &sal);
printf("Enter Phone: ");
scanf("%s", phno);
insertAtFront(&head, createEmployee(ssn, name, dept, designation,
sal, phno));
break;
case 3:
deleteAtFront(&head);
break;
case 4:
deleteAtEnd(&head);
break;
case 5:
displayDLL(head);
break;
case 6:
printf("Number of employees: %d\n", countNodes(head));
break;
case 7:
printf("Exiting program.\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}