Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  circular
Language: C/C++
Code:
#include <iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class queue
{
    int n,r,f,a[20];
    public:
    queue()
    {
        n=5;
        f=-1;
        r=-1;
    }
    void insert();
    void delet();
void display();
};
    void queue::insert()
{
    int x;
    if(f==0&&r==n-1||(f==r+1))
        cout<<"full";
    else
    {
        cout<<"enter an element";
        cin>>x;
        r=(r+1)%n;
        a[r]=x;
    }
    if(f==-1)
        f++;
}
void queue::delet()
{
int el;
if(f==-1)
{
cout<<"queue is empty";
}
el=a[f];
    if(f==r)
{
f=r=-1;
}
else
{
f=f+1;
}
   
        cout<<"delete element is"<<el<<endl;
     
}
void queue::display()
{
if(f==-1&&r==-1)
cout<<"queue is emptyn";
else if(f==r)
{
cout<<"elemnt is"<<a[f]<<endl;
r=f=-1;
}
else if(f>r)
{
for(int i=f;i<n;i++)
cout<<a[i]<<"t";
}
for(int i=0;i<=r;i++)
{
cout<<a[i]<<"t";
}
}
else if(f<r)
{
cout<<"elements in queue aren";
for(int i=f;i<=r;i++)
{
cout<<a[i]<<"t";
}
}
}

int main()
{
    queue q;
    int ch,m;
    while(1)
    {
        cout<<"1.ins 2.del 3.diaplay 4.exitn";
        cout<<"enter choicen";
        cin>>ch;
   
    switch(ch)
    {
        case 1:q.insert();
                 break;         
        case 2:q.delet();
               break;
case 3:q.display();
break;           
         case 4:exit(0);
        default:cout<<"in";
    }
}
getch();
}

          
Comments: