#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node *prev,*next;
};
void last(struct node **q)
{
if(*q==NULL)
{
*q=(struct node*)malloc(sizeof(struct node));
printf("\nlist is empty\nEnter the data in node :");
scanf("%d",&(*q)->data);
(*q)->prev=NULL;
(*q)->next=NULL;
}
else
{
struct node *temp;
temp=*q;
temp->prev=(struct
node*)malloc(sizeof(struct node));
temp=temp->prev;
temp->next=(*q);
(*q)->prev=temp;
temp->prev=NULL;
printf("\nenter the data in the Begining : ");
scanf("%d",&temp->data);
(*q)=temp;
}
printf("\nnode is created
successfully!!");
}
void display(struct node *q)
{
struct node *temp;
temp=q;
printf("\nnow the list is : ");
while(temp!=NULL)
{
printf(" %d",temp->data);
temp=temp->next;
}
}
void main()
{
struct node *start;
struct node **q;
clrscr();
start=NULL;
last(&start);
last(&start);
last(&start);
last(&start);
display(start);
getch();
}
No comments:
Post a Comment