To create a doubly link list using C


Levels of difficulty: / perform operation:

C Program

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
struct linklist
{
	struct linklist *prev;
	int num;
	struct linklist *next;
};
typedef struct linklist node;
void create(node *);
void display(node *);
void main()
{
	node *head;
	clrscr();
	head=(node *) malloc(sizeof(node));
	head->prev=NULL;
	create(head);
	printf("\n");
	display(head);
	getch();
}
void create(node *list)
{
	char conf='y';
	int i;
	printf("\nENTER A NUMBER: ");
	scanf("%d",&list->num);
	list->next->prev=list;
	printf("\nWANT TO CONTINUE[Y/N]: ");
	conf=getche();
	printf("\n");
	if(conf=='n' || conf=='N')
		list->next=NULL;
	else
	{
		list->next=(node *) malloc(sizeof(node));
		create(list->next);
	}
}
void display(node *disp)
{
printf("THE ADDRESS-PREVIOUS ADDRESS-VALUE-NEXT ADDRESS OF THE LINK LIST ARE:\n");
	while(disp!=NULL)
	{
		printf("%u-%u-%u-%u\n",disp,disp->prev,disp->num,disp->next);
		disp=disp->next;
	}
}


Output







Quantitative Aptitude
Reasoning
Programming
Interview