WAP to create double linked list


/*WAP to create double linked list*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
 int data;
 struct node *llink;
 struct node *rlink;
};
typedef struct node node;
void create(node *);

void main()
{
 node *header=NULL;
 int n;
 clrscr();
    header=(node*)malloc(sizeof(node));
    header->data=NULL;
    header->llink=NULL;
    header->rlink=NULL;
    create(header);
 
 getch();
}
void create(node *temphead)
{
 node *temp;
 char a='y';
 while(a=='y')
 {
  temp=(node *)malloc(sizeof(node));
  printf("Enter data:");
  scanf("%d",&temp->data);
  temp->rlink=NULL;
  temphead->llink=temphead;
  temphead->rlink=temp;
  printf("Do you want to create more??????");
  fflush(stdin);
  scanf("%c",&a);
  temphead=temp;
 }
}

No comments:

Post a Comment