deque容器的最最最简单操作

//#include "stdafx.h"
//#pragma warning(disable:4996)
#include <iostream> 
#include <algorithm>
#include <deque>

using namespace std;

deque<int> d;

void show(deque<int> &tem_d)
{
    for (deque<int>::iterator it = tem_d.begin(); it != tem_d.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;
}

int main()
{
    d.push_back(1);
    d.push_back(3);
    d.push_front(-1);
    d.push_front(-3);
    show(d);

    deque<int>::iterator it = find(d.begin(), d.end(), -1);         //查找指定元素的下标
    if (it != d.end())
        cout << "元素-1的下标为:" << distance(d.begin(), it) << endl;
    else
        cout << "没有元素-1" << endl;

    cout << "头部元素:" << d.front() << endl;
    cout << "尾部元素:" << d.back() << endl;

    cout << "修改头部元素:" << endl;
    d.front() = -11;
    show(d);
    cout << "修改尾部元素:" << endl;
    d.back() = 33;
    show(d);

    cout << "删除头部元素:" << endl;
    d.pop_front();
    show(d);
    cout << "删除尾部元素:" << endl;
    d.pop_back();
    show(d);

    cout << endl;
    system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值