C++STL学习笔记_(2)deque双端数组知识

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

void printD(deque <int> &d)
{
    for (deque<int>::iterator it = d.begin();it != d.end();it++)
    {
        cout<<*it<<endl;
    }
}
void main41()
{
    deque<int> d1;
    //尾部放入三个元素
    d1.push_back(1);
    d1.push_back(3);
    d1.push_back(5);

    d1.push_front(-11);
    d1.push_front(-33);
    d1.push_front(-55);

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

    printD(d1);
    
    d1.pop_front();
    d1.pop_back();
    printD(d1);

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

}
void main()
{
    main41();
    cout<<"hello...\n"<<endl;
    system("pause");
    return;
}

 

转载于:https://www.cnblogs.com/wuchuanying/p/6257886.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值