#include<iostream>
using namespace std;
#include"deque"
#include"algorithm"

void printD(deque<int> &d1)     //输出deque<int>型容器
{
    for (deque<int>::iterator it = d1.begin(); it != d1.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;
}


void f1()
{
    //在头部或者尾部插入元素
    deque<int> d1;
    d1.push_back(1);
    d1.push_back(3);
    d1.push_back(5);
    d1.push_front(-5);
    d1.push_front(-3);
    d1.push_front(-1);
    printD(d1);         //输出结果为: -1 -3 -5 1 3 5

    //在头部或者尾部弹出一个元素
    d1.pop_back();
    d1.pop_front();
    printD(d1);         //输出结果为: -3 -5 1 3

    //查找1在数组下标的值
    deque<int>::iterator it = find(d1.begin(), d1.end(), 1);
    if (it != d1.end())
    {
        cout << "值为1的数组下标为: " <<  distance(d1.begin(), it) << endl;
    }
    else
    {
        cout << "未找到值为1的元素" << endl;
    }
}

int main()
{
    f1();
    return 0;
}