Professional Documents
Culture Documents
#include <bits/stdc++.h>
class Queue
int front,rear;
public:
int a[MAX];
Queue(){
front=rear=-1;
int pop();
int fronts();
int back();
bool isEmpty();
};
return a[front];
return a[rear];
bool Queue::push(int x)
{
if(rear>=MAX-1)
cout<<"Queue is full";
return false;
else{
if(front==-1){
front=rear=0;
a[front]=x;
return true;
else{
a[++rear]=x;
return true;
int Queue::pop()
if(front==-1){
cout<<"Queue is empty";
return -1;
int x=a[front];
front=rear=-1;
return x;
else{
int x=a[front++];
return x;
int main()
Queue q;
q.push(10);
q.push(20);
q.push(30);
q.push(40);
q.pop();
q.push(50);
while(!q.isEmpty())
cout<<q.fronts()<<" ";
q.pop();
return 0;