#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
int data;
struct node *prev;
struct node *next;
};
void append(struct node **q)
{
struct node *temp;
temp=*q;
if(temp==NULL)
{
(*q)=(struct node *)malloc(sizeof(struct node));
scanf("%d",&(*q)->data);
(*q)->next=NULL;
(*q)->prev=NULL;
}
else
{
while(temp->next!=NULL)
temp=temp->next;
temp->next=(struct node *)malloc(sizeof(struct node));
temp=temp->next;
scanf("%d",&temp->data);
temp->next=NULL;
temp->prev=NULL;
}
}
void display(struct node *q)
{
struct node *temp;
temp=q;
while(temp!=NULL)
{
printf(" %d",temp->data);
temp=temp->next;
}
getch();
}
void append2(struct node **q) //DLL to CLL
{
struct node *temp;
temp=*q;
while(temp!=NULL)
temp=temp->next;
temp->next=(*q);
}
void display2(struct node *q)
{
struct node *temp;
temp=q;
while(temp->next!=q)
{
printf(" %d",temp->data);
temp=temp->next;
}
getch();
}
void main()
{
struct node *start;
start=NULL;
clrscr();
printf("\nenter the Doubly Link
List");
append(&start);
append(&start);
append(&start);
printf("\nthe Following Doubly Link
List");
display(start);
append2(&start);
printf("\nList After Conversion Circular Link List");
display2(start);
getch();
No comments:
Post a Comment