Tuesday, April 7, 2015

Convert of Singly Link List into Circular Link List.Write a programm to Convert of Singly Link List into Circular Link List.



WAP to convert SLL into DLL.


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
 int data;

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

   }
}
void display(struct node *q)
{
 struct node *temp;
  temp=q;
   while(temp!=NULL)
    {
     printf(" %d",temp->data);
      temp=temp->next;
    }
}
void append2(struct node **q)   //Function of making SLL into 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 Singly Link List");
  append(&start);
  append(&start);
  append(&start);
 printf("\nthe Fllowing Singly Link List");
  display(start);
  append2(&start);
  printf("\nAfter Conversion of Singly Link List into Circular Link List");
  display2(start);
 getch();
}

The following will be the output :
SLL to CLL

No comments:

Post a Comment