Doubly Linked List
Doubly Linked List
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
struct node {
struct node *prev;
int id;
char emp_name[40];
struct node *next;
}*start, *node, *new_node;
int main() {
int ch, n, m, pos, i;
char e_name[40];
start = NULL;
node -> prev = NULL;
node -> next = NULL;
clrscr();
while(1) {
printf("Enter choice : \n");
printf("1. Create List\n");
printf("2. Add at Beginning\n");
printf("3. Delete at End\n");
printf("4. Display\n");
printf("5. Quit\n");
scanf("%d", &ch);
switch (ch) {
case 1:
case 2:
printf("Enter Roll Number :");
scanf("%d", &m);
printf("Enter Name : ");
scanf("%s", e_name);
Add_at_beg(m, e_name);
Display();
break;
case 3:
Delete_at_end();
break;
case 4:
Display();
break;
case 5:
exit(0);
default :
printf("Wrong choice");
}
}
}
int Display() {
struct node *node;
if(start == NULL) {
printf("List is Empty!");
return 0;
}
node = start;
while(node != NULL) {
printf("%d\t%s \n", node -> id, node -> emp_name);
node = node -> next;
}
printf("\n");
return 0;
}
int Delete_at_end() {
node = start;
if (node == NULL) {
printf("Underflow!");
return 0;
}
while(node -> next -> next != NULL) {
node = node -> next;
}
node -> next -> prev = NULL;
node -> next = NULL;
Display();
return 0;
}