Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Circular Linked List in C++

Program for the implementation of  Circular Linked List in C++ language. In this program you can insert in circular link list, although the output seems as the singular link list but the code is written for circular list. Further addition if circular display function for viewing the operation don in the list. In Circular Linked List ending node not having the null value. Last node again point to starting node that's why it called as Circular Linked list.


Source Code:-

#include<iostream.h>
#include<conio.h>
#include<malloc.h>
struct node
{int info;
struct node *next;
}*start, *temp,*current;

void circular(int);
void circulardisplay();

void main()
{clrscr();
start=NULL;
int item,choice,location,element,position;
cout<<endl<<"Circular Singly Linked List by-Tarun Rawat\n";
again:

cout<<"\n1.Insert Item in Circular Linked List\n2.Display circular Linked List \n3.Exit\n";
cout<<"Enter choice : ";
cin>>choice;
switch(choice)
{case 1:cout<<"Enter item to insert: ";
       cin>>item;
       circular(item);
       goto again;
case 2:cout<<"\nInserted item = ";
       circulardisplay();cout<<"\n";
       goto again;
case 3:cout<<"\nTHANK YOU";
default:break;
}
getch();
}

void circular(int item)
{temp=(node*)malloc(sizeof(node));
temp->info=item;
temp->next=start;
node* current;
if(start==NULL)
{start=temp;
temp->next=start;
}
else
{current=start;
 while(current->next!=start)
  {current=current->next;
  }
 current->next=temp;
 }
}

void circulardisplay()
{current= start;
 do{
 cout<<current->info<<" ";
 current=current->next;
 }while(current!=start);

}


4 comments:

  1. what happing in this program tell me in simple words

    ReplyDelete
  2. Good code. But what about insertion and deletion from different ends or middle of the circular linked list? Here is a good example for that circular linked list C++ program.

    ReplyDelete
  3. FavTutor

    Nice !!

    https://favtutor.com/blogs/sorting-algorithms-java

    ReplyDelete
  4. Are you searching for data science projects for beginners? Here statanalytica provides 25 best-ever data science projects for beginners.

    ReplyDelete

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)