0% found this document useful (0 votes)
6 views2 pages

Java

This document contains a C program that implements a doubly linked list with operations to insert a node at the beginning and display the list. It defines a structure for the nodes and includes functions for insertion and display. The main function provides a menu for user interaction to perform these operations.

Uploaded by

23201117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Java

This document contains a C program that implements a doubly linked list with operations to insert a node at the beginning and display the list. It defines a structure for the nodes and includes functions for insertion and display. The main function provides a menu for user interaction to perform these operations.

Uploaded by

23201117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

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);

printf("\nprinting values . . . . .\n");


while (ptr!=NULL)
{
printf("%p-> ",ptr->prev);
printf("%d-> \t",ptr->data);
printf("%p-> \n",ptr->next);
ptr = ptr -> next;
}

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..");
}
}
}

You might also like