21 September, 2018
A linked list in which the last node points to the first node instead of containing null pointer will be termed as circularly linked list or simply circular list Circular linked list in data structures have an advantages over singly linked list. It is concerned with the accessibility of a node. Ina circular list every node is accessible from a given node that is, from this given node all nodes can be reached by changing through the list.
cur 1= Head; Head=cur; ptr
1=Head;
cur link = ptr à link; ptr1
link =cur;
Head =ptr1 link; ptr
link =Head; free(ptr);
temp=ptrl link; ptr1
link = ptr1
link à link free(temp);
Implementaton of circular linked list # include <studio.h> #include <conio.h> # define NULL #include<stdlib.h> struct Node { int data; struct Node*link; }; struct node*Head; void create() { int a; struct Node * cur,*ptr; Head=NULL; printf(“Enter Data For The Node(-1):”); scanf(“%d%,&a); while(a!=-1) { cur =(struct Node *) malloc (size of (struct Node)); curdata =a; cur
link =NULL; if(Head== NULL) Head==cur; else ptr= cur; printf(“Enter Data For Node (-1):”); scanf (“%d”,&a); } ptr
link =Head; } void insert() { int ele; char ch; struct Node*ftr, *ptr,*ptr1,*cur; ptr=Head; ptr1=Head; cur=(struct Node *) malloc (size of (struct Nodes); printf(“Enter data:”); scanf(“%d”,&cur àdata); cur
link =NULL; printf(“Do you want to insert first(y\n):”); flush(stdin); scanf(“%c”,&ch); if((ch==’y’) || (ch==’y’)) { while(ptr
link!=Head) { ptr=ptr
link; } cur
link =Head; Head= cur; ptr à link =Head; } else { printf(“After which element you want to insert:”); scanf(“%d”,&ele); do { if( ptr1
data == ele) { cur
link =ptr1
link; ptr1
link =cur; } ptr1 = ptr1
link; } while(ptr1!=Head); } } void deletion() { int ele; char ch; struct Node *temp,*ptr,*ptr1; ptr=ptr1=Head; fflush(stdin); printf(“Do you want to delete first(y\n):”); scanf(“%c”,&ch); if((ch==’y’)|| (ch==’y’)) { while(ptr
link!=Head) { ptr= ptr
link; } cur
link =Head; Head= cur; ptr
link =Head; } else { printf(“After which element you want to insert:”); scanf(“%d”,&ele); do { if(ptr1
data ==ele) { cur
link=ptr1
link; ptr1
link =cur; } ptr1 =ptr1 àlink; } while(ptr1!=Head); } } void deletion() { int ele; char ch; struct Node *temp,*ptr,*ptr1; ptr=ptr1=Head; fflush(stdin); printf(“Do you want to delete first (y/n):”); scanf(“%c”,&ch); if((ch==’y’) || (ch==’y’)) { while(ptr
link!=Head) { ptr = ptr
link; } Head =ptr1
link; ptr
link =Head; free(ptr1); } printf(“Which element you want to delete:”); scanf(“%d”,&ele); do { if(ptr1
link
data == ele) { temp=ptr1
link; ptr1
link = ptr1
link
link; free(temp); break; } else { } while(ptr1!=Head) } } void display() { struct Node * temp; temp=Head; do { printf(“%d”
,temp
data); temp=temp
link; } while(temp!= Head); } } void main() { int op; clrscr(); create(); printf(“1.INSERTION \n”); printf(“2.DELETION \n”); printf(“3.DISPLAY \n”); printf(“4.EXIT \n”); do { printf(“Enter your option:\n”); scanf(“%d”,&op); switch (op) { { case1: insertion (); break; case2: deletion (); break; case3: Display(); break; case4: exit(0); } } while (op<=4); }
TekSlate
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .