PAT乙题1008

答案

#include 
#include
#include
using namespace std;
deque q;
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        q.push_back(x);
    }
    while (m--)
    {
        int temp = q.back();
        q.pop_back();
        q.push_front(temp);
    }
    for (auto t = q.begin(); t != q.end(); t++)
    {
        cout << *t;
        if (t + 1 != q.end()) cout << ' ';
    }
    return 0;
}

不太会这个双端队列deque的用法,跟queue有什么区别吗

还有此题的出队首和队尾,弹出队首队尾,在队首前插入数

以及auto用法,顺序输出队列所有数

你可能感兴趣的:(算法,c++,数据结构)