"circular queue using linked list in c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "circular queue using linked list in c++" answered properly. Developers are finding an appropriate answer about circular queue using linked list in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like circular queue using linked list in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on circular queue using linked list in c++.
circular queue using linked list in c++
#include<iostream>
#define SIZE 100
using namespace std;
class node
{
public:
node()
{
next = NULL;
}
int data;
node *next;
}*front=NULL,*rear=NULL,*n,*temp,*temp1;
class cqueue
{
public:
void insertion();
void deletion();
void display();
};
int main()
{
cqueue cqobj;
int ch;
do
{
cout<<"\n\n\tMain Menu";
cout<<"\n##########################";
cout<<"\n1. Insert\n2. Delete\n3. Display\n4. Exit\n\nEnter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1:
cqobj.insertion();
cqobj.display();
break;
case 2:
cqobj.deletion();
break;
case 3:
cqobj.display();
break;
case 4:
break;
default:
cout<<"\n\nWrong Choice!!! Try Again.";
}
}while(ch!=4);
return 0;
}
void cqueue::insertion()
{
n=new node[sizeof(node)];
cout<<"\nEnter the Element: ";
cin>>n->data;
if(front==NULL)
{
front=n;
}
else
{
rear->next=n;
}
rear=n;
rear->next=front;
}
void cqueue::deletion()
{
int x;
temp=front;
if(front==NULL)
{
cout<<"\nCircular Queue Empty!!!";
}
else
{
if(front==rear)
{
x=front->data;
delete(temp);
front=NULL;
rear=NULL;
}
else
{
x=temp->data;
front=front->next;
rear->next=front;
delete(temp);
}
cout<<"\nElement "<<x<<" is Deleted";
display();
}
}
void cqueue::display()
{
temp=front;
temp1=NULL;
if(front==NULL)
{
cout<<"\n\nCircular Queue Empty!!!";
}
else
{
cout<<"\n\nCircular Queue Elements are:\n\n";
while(temp!=temp1)
{
cout<<temp->data<<" ";
temp=temp->next;
temp1=front;
}
}
}
All those coders who are working on the C++ based application and are stuck on circular queue using linked list in c++ can get a collection of related answers to their query. Programmers need to enter their query on circular queue using linked list in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about circular queue using linked list in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of circular queue using linked list in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "circular queue using linked list in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like circular queue using linked list in c++ resolved professionally and stay updated to the latest C++ updates.