c program :
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
struct node *prev;
};
struct node *head = NULL;
struct node *create(int item)
{
struct node *new, *ptr;
new = malloc(sizeof(struct node));
if (new == NULL)
printf("\nLIST OVERFLOW");
else
{
new->data = item;
new->next = NULL;
new->prev=NULL;
if (head == NULL)
{
head = new;
}
else
{
ptr = head;
while (ptr->next != NULL)
{
ptr = ptr->next;
}
ptr->next = new;
new->prev=ptr;
}
}
return head;
}
void display()
{
struct node *ptr;
if (head == NULL)
printf("\nLIST IS EMPTY");
else
{
ptr = head;
while (ptr != NULL)
{
printf("%3d", ptr->data);
ptr = ptr->next;
}
}
}
int main()
{
int choice, item, l;
do
{
printf("\nSLL OPERATIONS");
printf("\n1.CREATE\n2.DISPLAY\n3.EXIT");
printf("\nENTER CHOICE:");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\nENTER ITEM TO INSERT:");
scanf("%d", &item);
head = create(item);
printf("\nNODE INSERTED");
break;
case 2:
display();
break;
case 3:
exit(0);
break;
default:
printf("\nwrong choice");
}
} while (choice != 3);
return 0;
}
Comments