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;
    }
  }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
queue using circular linked list c++ a circular queue is implement using a single linked list circular linked list vs circular queue circular queue linked list implementation in c circular linked list implement queue is queue a circular linked list why can we implement circular queue using linked list circular queue linked list implementation circular queue and circular linked list same? circular queue using circular linked list c++ How will you represent circular linked list as queue. implement circular queue using linked list in c c++ program for circular queue using linked list circular queue using singly linked list circular linked queue linked list implementation of circular queue in c circular queue with linked list circular queue and its implementation in linked list circular queue in c++ using linked list a circular linked list is used to represent a queue circular linked list is used to represent a queue queue with circular linked list in c++ implementation of queue using circular linked list Simple Queue as a Circular Linked List circular queue program in c using linked list circular queue implementation using linked list algorithm for implementation of circular queue using linked list Implement the queue with circular linked list in c++ queue using circular linked list c ++ circular queue linked list circular linked queue implementation circular queue using linked list circular queue in c++ circular linked list queue in c circular linked list queue circular queue implementation in c using linked list represent linked list as circular queue c program to implement circular queue using linked list program to implement circular queue using linked list. how to make a circularly linked list C++ stack using circular linked list in c++ circular queue using linked list in c implementation of circular queue using linked list in c circular queue using linked list in c c program for circular queue using linked list .Code to search element in a Circular Linked list. C++ Code to Create circular Linked list. C++ circular queue using linked list - sanfoundry Queue - Linked List Implementation Consider implementing a Circular Queue using a Linked List. queue using circular linked list implement a queue using circular linked list Circular Linked List in c++ circular queue using linked list in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source