队列也是比较简单的数据结构了,队列的特点是先进先出
下面代码中hh是队头,tt是队尾。
默认是从队尾插入数据,队头弹出数据。

代码中的数据结构可以使用这图片来解释,整个区间是数组q。hh和tt分别控制队头和队尾。
例题:https://www.acwing.com/activity/content/problem/content/866/
#include<iostream>
using namespace std;
const int N=1e5+10;
int q[N],hh,tt=-1;
int main()
{
    int m,x;
    cin>>m;
    while(m--)
    {
        string op;
        cin>>op;
        if(op=="push")
        {
            //向队尾插入一个元素
            cin>>x;
            q[++tt]=x;
        }
        if(op=="pop")
        {
            //向队头弹出一个数
            hh++;
        }
        if(op=="empty")
        {
            //判断队列是否为空
            if(tt>=hh)
            {
                cout<<"NO"<<endl;
            }
            else
            {
                cout<<"YES"<<endl;
            }
        }
        if(op=="query")
        {
            //查询队头元素
            cout<<q[hh]<<endl;
        }
    }
    
    
    return 0;
} 



















