Advertisment

Circular linked list

Circular list is a list in which the link field of the last node is made to point to the start/first node of the list.




Points to Circular Linked List

1.A circular linked list is a linked list in which the head element's previous pointer points to the tail element and the tail element's next pointer points to the head element.
2.A circularly linked list node looks exactly the same as a linear singly linked list.



Circular linked list

/* CREATING CIRCULAR HEADER LINKED LIST */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct link
{
	int data;
	struct link *next;
};
int i=0;
struct link *node,*start;

void create_link(struct link *node)
{
	char ch;
	start->next=NULL;
	node=start;
	fflush(stdin);
	printf("\n Enter 'n' for break:");
	ch=getchar();
	while(ch!='n')
	{
		node->next=(struct link *)malloc(sizeof(struct link));
		node=node->next;

		printf("\n Enter data for node:");
		scanf("%d",&node->data);
		node->next=start;
		fflush(stdin);
		printf("\n Enter 'n' for break:");
		ch=getchar();
		i++;
	}
}

void display(struct link *node)
{
	int count;
	node=start->next;
	count=i;

	while(count)
	{
		printf("\t  %d",node->data);
		node=node->next;
		count--;
	}
}

void main()
{
	char ch;
	clrscr();
	create_link(node);
	printf("List Item Are:-\n");
	display(node);
	getch();
}

Output