Java
Java
h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
struct node *prev;
};
struct node *head=NULL;
void beginsert()
{
struct node *ptr;
int item;
ptr = malloc(sizeof(struct node *));
printf("\nEnter value\n");
scanf("%d",&item);
ptr->data = item;
ptr->next = head;
ptr->prev= NULL;
if (head!=NULL)
head->prev=ptr;
head = ptr;
printf("\nNode inserted");
void display()
{
struct node *ptr;
ptr = head;
printf("Position of head %p-> ",head);
void main ()
{
int choice =0;
while(1)
{
printf("\nDoubly linked list operations\nChoose one option from the
following list ...\n");
printf("\n1.Insert in beginning\n2.Show\n3.Exit\n");
printf("\nEnter your choice?\n");
scanf("\n%d",&choice);
switch(choice)
{
case 1:
beginsert();
break;
case 2:
display();
break;
case 3:
exit(0);
break;
default:
printf("Please enter valid choice..");
}
}
}