//优先队列
#include<iostream>
using namespace std;
class Queue
{
private:
struct Node //创建一个节点信息,包括数据和优先级
{
int data;
int level;
Node() :data(), level(-1){}
Node(int data_, int level_) :data(data_), level(level_){}
};
Node datas[5];
int front; //队首
int back; //队尾
int cont; //有效个数
public:
Queue() :front(), back(), cont(){}
void push(int data, int level) //压入数据
{
if (full()) //验满
{
cout << "满" << endl;
cin.get();
exit(1);
}
int temp = front;
for (int i = 0; i < cont; i++) //验证优先级
{
if (datas[temp%5].level < level) //把优先级别高的节点放在前面
{
Node t1 = datas[temp % 5];
datas[temp % 5] = { data, level };
for (int j = i; j < cont; j++)
{
Node t2 = datas[(temp + 1) % 5];
temp++;
datas[temp % 5] = t1;
t1 = t2;
}
back++; //队尾往后移一个
cont++; //有效个数加一
return;
}
temp++;
}
datas[back++ % 5] = { data, level };//如果当前数字优先级别最小,则放在队尾
cont++;
}
int pop() //弹出数据
{
if (empty())
{
cerr << "空" << endl;
cin.get();
exit(1);
}
cont--;
return datas[front++ % 5].data;
}
int get_front() //获取队首数据
{
return datas[front].data;
}
int get_back() //获取队尾数据
{
return datas[back].data;
}
void clear() //清空队列
{
front = cont = back = 0;
}
bool full() //判满
{
return cont > 4;
}
bool empty() //判空
{
return cont == 0;
}
int size()
{
return cont;
}
};
int main()
{
cin.get();
return 0;
}