#include <iostream>
using namespace std;
class Que{
int arr[100];
int front,rear;
public:
Que(){
front=rear=-1;
}
void push(int x){
if(front==-1) front=0;
arr[++rear]=x;
}
int pop(){
if(front==-1||front>rear){
cout<<"underflow";
return -999;
}
int x= arr[++front];
if(front>rear){
front=-1;
rear=-1;
}
return x;
}
void show(){
if(front!=-1){
for(int i=front;i<=rear;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
}
};
int main()
{
Que q;
q.push(10);
q.push(80);
q.show();
q.push(78);
q.show();
q.pop();
q.show();
return 0;
}
No comments:
Post a Comment