#include<iostream>
using namespace std;
const int size=5;
class cqueue
{
private:
int cq[size];
int front,rear,data;
public:
cqueue()
{
front=-1;
rear=-1;
}
void insert(int n)
{
if(front==((rear+1)%size))
{
cout<<"queue is full."<<endl;
}
else if(rear==-1&&front==-1)
{
rear=0;
front=0;
cq[rear]=n;
cout<<"inserted data is:"<<cq[rear]<<endl;
}
else
{
rear=(rear+1)%size;
cq[rear]=n;
cout<<"inserted data is:"<<cq[rear]<<endl;
}
}
void deldata()
{
if(front==(rear+1))
{
cout<<"queue is empty."<<endl;
}
else
{
data=cq[front];
cq[front]=NULL;
cout<<"deleted data:"<<data<<endl;
front=(front+1)%size;
//front=front+1;
}
}
void view()
{
cout<<"f="<<front<<endl;
cout<<"r="<<rear<<endl;
}
};
int main()
{
cqueue c1;
c1.insert(10);
c1.insert(20);
c1.insert(30);
c1.insert(40);
c1.insert(50);
c1.insert(60);
c1.deldata();
c1.deldata();
c1.deldata();
c1.deldata();
c1.view();
c1.insert(60);
c1.insert(70);
c1.insert(80);
c1.insert(90);
c1.insert(80);
c1.insert(90);
c1.view();
return 0;
}
0 comments:
Post a Comment