# Program of Circular Linked List

Circular Linked List is another remedy for the drawbacks of the Single Linked List besides Doubly Linked List. A Slight change to the structure of a linear list is made to convert it to circular linked list; link field in the last node contains a pointer back to the first not Null.

## /* Program of circular linked list*/

# include <stdio.h>

# include <malloc.h>

struct nodee

{

int infoo;

}*lastt;

main()

{

int choicee,no,mm,poo,ii;

lastt=NULL;

while(1)

{

printf("Press 1...Create List\n");

printf("Press 2..Add at begining\n");

printf("Press 3...Add after \n");

printf("Press 4...Delete\n");

printf("Press 5...Display\n");

printf("Press 6...Quit\n");

printf("Enter your choicee : ");

scanf("%d",&choicee);

switch(choicee)

{

case 1:

printf("Enter the node......> : "); /* to be created*/

scanf("%d",&no);

for(ii=0; ii < no;ii++)

{

printf("Enter the data(number) value.......> : \n");

scanf("%d",&mm);

create_list(mm);

}

break;

case 2:

printf("Enter the number(for beginning) .......> : ");

scanf("%d",&mm);

break;

case 3:

printf("Enter the number(for any position)........> : ");

scanf("%d",&mm);

printf("Enter the poosition......>\n ");

scanf("%d",&poo);

break;

case 4:

if(lastt == NULL)

{

printf("Oops! List underflow\n");

continue;

}

printf("Enter the any(for deletion) one number......>:\n ");

scanf("%d",&mm);

del(mm);

break;

case 5:

display();

break;

case 6:

exit();

default:

printf("Wrong choicee\n");

}/* switch End*/

}/* while End*/

}/* main() End*/

create_list(int numm)

{

struct nodee *qq,*tmpp;

tmpp= malloc(sizeof(struct nodee));

tmpp->infoo = numm;

if(lastt == NULL)

{

lastt = tmpp;

}

else

{

lastt = tmpp;

}

}/* create_list() End*/

{

struct nodee *tmpp;

tmpp = malloc(sizeof(struct nodee));

tmpp->infoo = numm;

{

struct nodee *tmpp,*qq;

int ii;

for(ii=0; ii < poos-1; ii++)

{

{

printf("There are less than %d elements\n",poos);

return;

}

}/* for End*/

tmpp = malloc(sizeof(struct nodee) );

tmpp->infoo = numm;

if(qq==lastt)    /*Element inserted at the end*/

lastt=tmpp;

del(int numm)

{

struct nodee *tmpp,*qq;

if( lastt->linkk == lastt && lastt->infoo == numm)  /*Only one element*/

{

tmpp = lastt;

lastt = NULL;

free(tmpp);

return;

}

if(qq->infoo == numm)

{

tmpp = qq;

free(tmpp);

return;

}

{

if(qq->linkk->infoo == numm)     /*Element deleted in between*/

{

free(tmpp);

printf("%d deleted\n",numm);

return;

}

}/* while End*/

if(qq->linkk->infoo == numm)    /*lastt element deleted qq->linkk=lastt*/

{

free(tmpp);

lastt = qq;

return;

}

}/* del() End*/

display()

{

struct nodee *qq;

if(lastt == NULL)

{

printf("List is empty\n");

return;

}

printf("List is :\n");

while(qq != lastt)

{

printf("%d ", qq->infoo);

}

printf("%d\n",lastt->infoo);

}/* display() End*/