#include<iostream>
#include<string>
using namespace std;
#define size 10
class Queue{
public:
Queue();
void ruQueue(int n);
void chuQueue();
void show();
private:
int front;
int end;
int number;
int a[size];
};
Queue::Queue(){
front = end = number = 0;
}
void Queue::ruQueue(int n){
if(number == size){
cout<<"queue is full!!"<<endl;
return;
}
else{
number++;
a[end] = n;
end=(end+1)%size;
}
}
void Queue::chuQueue(){
if(number == 0){
cout<<"queue is empty!!"<<endl;
return;
}
else{
number--;
cout<<" 出队列元素为:"<<a[front]<<endl;
front = (front+1)%size;
}
}
void Queue::show(){
cout<<"队列元素个数为:"<<number<<endl;
}
int main(){
class Queue que;
que.ruQueue(2);
que.ruQueue(4);
que.ruQueue(6);
que.show();
que.chuQueue();
que.chuQueue();
que.show();
}
#include<string>
using namespace std;
#define size 10
class Queue{
public:
Queue();
void ruQueue(int n);
void chuQueue();
void show();
private:
int front;
int end;
int number;
int a[size];
};
Queue::Queue(){
front = end = number = 0;
}
void Queue::ruQueue(int n){
if(number == size){
cout<<"queue is full!!"<<endl;
return;
}
else{
number++;
a[end] = n;
end=(end+1)%size;
}
}
void Queue::chuQueue(){
if(number == 0){
cout<<"queue is empty!!"<<endl;
return;
}
else{
number--;
cout<<" 出队列元素为:"<<a[front]<<endl;
front = (front+1)%size;
}
}
void Queue::show(){
cout<<"队列元素个数为:"<<number<<endl;
}
int main(){
class Queue que;
que.ruQueue(2);
que.ruQueue(4);
que.ruQueue(6);
que.show();
que.chuQueue();
que.chuQueue();
que.show();
}