队列
queue <int> q;
q.push(i);
q.pop();
q.front();
q.back();
q.size();
q.empty();
双端队列
#include<deque>
deque<int> q;
q.push_front(x);
q.push_back(x);
q.pop_front();
q.pop_back();
q.clear();
q.empty();
q.size();
c++循环队列
typedef struct queue{
int count;
int front;
int rear;
int data[MAX_SIZE];
}Queue;
void Init(Queue *ptr)
{
ptr->count=0;
ptr->rear=-1;
ptr->front=0;
}
bool QueueFull(Queue *ptr)
{
return ptr->count>=MAX_SIZE;
}
bool QueueEmpty(Queue *ptr)
{
return ptr->count<=0;
}
void Append(Queue *ptr,int item)
{
if(QueueFull(ptr))
{
cout<<"满了";
return;
}
else{
ptr->count++;
ptr->rear=(ptr->rear+1)%MAX_SIZE;
ptr->data[ptr->rear]=item;
}
}
void Pop(Queue *ptr)
{
if(QueueEmpty(ptr))
{
cout<<"队列为空";
return;
}
else{
ptr->count--;
ptr->front=(ptr->front+1)%MAX_SIZE;
}
}