top of page
Writer's pictureApurba Paul

Circular Linked List-Singular-Part 1

Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end. A circular linked list can be a singly circular linked list or doubly circular linked list.


#include<stdio.h>

typedef struct mynode { int info; struct mynode *Link; }Node; Node *start=NULL,*start2=NULL; //Display Function void display() { Node *tptr=start->Link; printf("\nDATA:\n"); printf("->%d",start->info); while(tptr!=start) { printf("->%d",tptr->info); tptr=tptr->Link; } } //Insertion at the End function void add_node(int value) { Node *newp=NULL,*tptr=NULL; newp=(Node*)malloc(sizeof(Node)); newp->info=value; newp->Link=NULL; if(start==NULL) { start=newp; } else { tptr=start; while(tptr->Link!=start) { tptr=tptr->Link; } tptr->Link=newp; } newp->Link=start; } //Main int main() { int value; char choice; while(1) {   printf("Do you want to insert(y/n)?");   scanf("%c",&choice);   if(choice == 'y') {   printf("\nEnter the info:");   scanf("%d",&value); add_node(value);   fflush(stdin); } else { break; } } display(); return 0; }

12 views0 comments

Recent Posts

See All

Comments


bottom of page