Saturday, May 9, 2009

PROGRAM FOR IMPLEMENTING CIRCULAR LINKED LIST

#include
#include
#include
struct cir
{
int info;
struct cir *next;
};
typedef struct cir node;
node *first,*temp,*new1,*list,*prev,*cur,*p;
void creat()
{
int ele;
printf("Type -1 to stop");
printf("\n Enter ele \t");
scanf("%d",&ele);
while(ele!=-1)
{
new1=(node *)malloc(sizeof(node));
new1->info=ele;
if(first==NULL)
{
new1->next=new1;
first=new1;
}
else
{
new1->next=first->next;
first->next=new1;
}
printf("enter ele\t");
scanf("%d",&ele);
}
}
void count()
{
int c=0;
temp=first;
first=first->next;
while(first!=temp)
{
++c;
first=first->next;
}
++c;
printf("No of nodes in circular list=%d",c);
}
void print()
{
node *start;
temp=first;
start=first->next;
printf("the circulat list is");
while(start!=temp)
{
printf("%d->",start->info);
start=start->next;
}
printf("%d",start->info);
}

No comments:

Post a Comment