C++ Programming Blog

 
 
 

Image

# include <iostream.h>
# include <process.h>
# include <conio.h>
int display_menu();
class circularqueue
{
  int arr[10];
  int front,rear;
  int size;
  public:
     circularqueue()
     {
      front=0;
      rear=0;
      size=10;
     }
     void display();
     void enqueue();
     void delete_element();
};

void circularqueue :: display()
{
 cout<<endl;
 if(front!=0 && rear!=0)
 {
        int i=front;
        cout<<\"arr[\"<<i<<\"] :\"<<arr[i]<<endl;
        while(i!=rear)
        {
         i=(i % size)+1;
         cout<<\"arr[\"<<i<<\"] :\"<<arr[i]<<endl;
        }

 }
 else
 {
    cout<<\"Queue is empty\"<<endl;
 }
 getch();
}

void circularqueue :: enqueue()
{
 cout<<endl;
 if(front==0 && rear==0)
 {
  cout<<\"Enter Number to enqueue at Position arr[\"<<rear+1<<\"] :\";
  cin>>arr[1];
  rear=1;
  front=1;
 }
 else
 {
  int next=(rear % size)+1;






  if(next==front)
  {
   cout<<\"Queue is Full ...\";
   getch();
  }
  else
  {
   cout<<\"Enter Number to enqueue at Position arr[\"<<next<<\"] :\";
   cin>>arr[next];
   rear=next;
  }
 }
}

void  circularqueue :: delete_element()
{
 cout<<endl;
 if(rear==0 && front==0)
 {
   cout<<\"Queue is empty ...\";
   getch();
   return;
 }


 if(rear==front)
 {
  rear=0;
  front=0;
 }
 else
 {
  front=(front % size)+1;
 }
}
void main()
{
 circularqueue cq1;
 while(1)
 {
  switch(display_menu())
  {
    case 1: cq1.enqueue();
        break;
    case 2: cq1.delete_element();
        break;
    case 3: cq1.display();
        break;
    case 4: exit(1);
  }
 }
}
int display_menu()
{
 int c;
 clrscr();
 cout<<endl;
 cout<<\"| 1 | : Enqueue element\"<<endl;
 cout<<\"| 2 | : Delete element\"<<endl;
 cout<<\"| 3 | : Display\"<<endl;
 cout<<\"| 4 | : Exit\"<<endl;
 cout<<\"Enter your Choice :\";
 cin>>c;
 return c;
}

    Related Post:
  1. Program that creats a 3D solid object using Translational Sweep Representatiom Method

  2. Represent a polynomial in terms of a singly linked list and then add two three variables polynomials

  3. Program to convert an Infix Expression into a Postfix Expression using Linked List as a Stack

  4. Program of addition and subtraction of large numbers

  5. Program that takes short date from a user and displays medium date

  6. Program that prints first 20 integers in reverse order (using while loop )

  7. Program that computes and display the square of first ten integers. (using for loop)

  8. Program to solve the mystery of Towers of Hanoi using recursion

  9. Program of disk editor

  10. Program of singly link list with different functionalities

  11. Library system using pointers

  12. Program that provides an example of function returning object

  13. Program to find the day of a week of a given date from 15 october 1582 to end of universe using arrays

  14. Program of circular doubly link list with insert, append, delete, copy, reverse and display operations

  15. Program that provides an example of static variables in class

  16. Program of nesting member functions, private member functions and array of objects

  17. Program to rotate the word Computer by 1 results in rCompute

  18. Program to illustrate constant objects and constant member functions

  19. Program that performs file read, write, update and display operations

  20. Program to sort that set of strings in ascending and descending order of their weights. The sorted output is to be displayed on the screen

 
 
Didn't find what you were looking for? Find more on Program to create a circular queue