#include <iostream>
#define MAX_SIZE 7
using namespace std;
class Stack
{
public:
Stack():front_sub(0),rear_sub(0)
{
}
int push(int value);//入队
void pop();//出队
void show();//输出
int size();//求队列长度
bool full();//判满
bool empty();//判空
private:
int arr[MAX_SIZE];//存放队列的数组
int front_sub;//队头的下表
int rear_sub;//队尾下表
};
int Stack::push(int value)
{
if(full())
{
return -1;//队列已满
}else
{
arr[rear_sub]=value;//入队
rear_sub =(rear_sub +1)% MAX_SIZE;
return 0;//入队成功
}
}
void Stack::pop()//出队
{
if(!empty())
{
front_sub=(front_sub+1)%MAX_SIZE;
}
}
void Stack::show()//输出
{
if(!empty())
{
for(int i=front_sub;i!=rear_sub;i=(i+1)%MAX_SIZE)
{
cout<<arr[i]<<"";
}
cout<<endl;
}
}
int Stack::size()//求队列长度
{
return (rear_sub + MAX_SIZE - front_sub)%MAX_SIZE;
}
bool Stack::full()//判满
{
return (rear_sub + 1) % MAX_SIZE == front_sub;
}
bool Stack::empty()//判空
{
return front_sub==rear_sub;
}
int main()
{
Stack s;
s.push(1);//入队
s.push(2);
\;
s.push(3);
s.push(4);
s.push(5);
s.show();//输出
cout<<"出队后";
s.pop();//出队
cout<<endl;
s.show();//输出
cout<<"队列长度= "<<s.size()<<endl;//队列长度
cout<<"是否队满= "<<s.full()<<endl;//是否队满
cout<<"是否为满= "<<s.empty()<<endl;//是否队满
return 0;
}