DLL Lab Program
DLL Lab Program
List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal,
PhNo
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];
};
typedef struct employee *NODE;
NODE getnode() {
if (!temp) {
exit(1);
return temp;
NODE create_list(int N) {
int i;
temp = getnode();
printf("SSN: ");
scanf("%d", &temp->SSN);
printf("Department: ");
printf("Designation: ");
printf("Salary: ");
scanf("%f", &temp->sal);
temp->next = NULL;
if (first == NULL) {
temp->prev = NULL;
first = temp;
} else {
cur = first;
cur = cur->next;
}
cur->next = temp;
temp->prev = cur;
return first;
if (first == NULL) {
printf("\nList is empty\n");
return;
int count = 0;
printf("SSN: %d, Name: %s, Dept: %s, Designation: %s, Salary: %.2f, Phone:
%s\n",
count++;
cur = cur->next;
}
NODE cur;
printf("\nEnter new employee details (SSN, Name, Dept, Designation, Salary, Phone
Number):\n");
printf("SSN: ");
scanf("%d", &temp->SSN);
printf("Name: ");
printf("Department: ");
printf("Designation: ");
printf("Salary: ");
scanf("%f", &temp->sal);
temp->next = NULL;
if (first == NULL) {
temp->prev = NULL;
return temp;
cur = first;
cur = cur->next;
cur->next = temp;
temp->prev = cur;
return first;
if (first == NULL) {
return 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",
free(cur);
return first;
}
// Function to insert at the front of the DLL
printf("\nEnter new employee details (SSN, Name, Dept, Designation, Salary, Phone
Number):\n");
printf("SSN: ");
scanf("%d", &temp->SSN);
printf("Name: ");
printf("Department: ");
printf("Designation: ");
printf("Salary: ");
scanf("%f", &temp->sal);
temp->next = first;
if (first != NULL) {
first->prev = temp;
return temp;
if (first == NULL) {
return NULL;
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",
free(temp);
return first;
// Main function
int main() {
int choice, N;
while (1) {
printf("\nMenu:\n");
printf("8. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
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: