Sunday 27 November 2011

C Program For Circular Link list


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
  struct list
  {
   int data;
   struct list*next;
  };
void main()
{
  struct list*temp*,start,*node;
  start=temp=node=null;
  int ch;
  clrscr();
  do{
     printf("1.add 2.display 3.exit");
scanf("%d",&ch);
if(ch == 1)
{
  node(struct list*)malloc(size of(struct list));
  if(start == null)
  {
    start node;
start->next=start;
start->pre=null;
  }
  else
  {
    temp = start;
while(temp->next!=start)
 {
   temp=temp->next;
 }
 temp->next=node;
 node->next=start;
  }
 }
 if(ch == 2)
 {
   for(temp=start;temp->data)
printf("%d",temp->data);
 }
 if(ch == 3)
 {
   for(temp=start;temp->next!=start;temp=temp->next)
printf("%d",temp->data);

 }

 if(ch == 4)
  exit(0);
}while(1);

getch();

}
  

No comments:

Post a Comment