当前位置: 首页 > news >正文

深圳华维网站建设包头seo

深圳华维网站建设,包头seo,wordpress采集淘宝 插件,上海招聘信息网官网目录 一、list 简介二、list 的常用接口1. 构造函数(constructor )2. 迭代器(iterator)3. 容量、修改和访问(capacity 、modify and access) 一、list 简介 简单来说,list 就是数据结构初阶中学…

目录

  • 一、list 简介
  • 二、list 的常用接口
    • 1. 构造函数(constructor )
    • 2. 迭代器(iterator)
    • 3. 容量、修改和访问(capacity 、modify and access)

一、list 简介

  简单来说,list 就是数据结构初阶中学习的链表,还是所有特性都具备的带头双向循环链表。带头是为了更好地适应迭代器,双向循环是为了插入和删除的效率。与之前学习的 list 相比,本次学习的 list 升级成为了类模板且增加了迭代器。

二、list 的常用接口

  下面介绍一下 list 各方面的常用接口。

1. 构造函数(constructor )

  下面是 list 常用的四个构造函数的声明和使用。

(1)函数声明

// list 构造函数声明// 1. 默认构造函数
list();
// 2. 指定个数和初始值
list(size_t n, const T& value = T());
// 3. 迭代器构造函数
template<class Iterator>
list(Iterator first, Iterator last);
// 4. 复制构造函数
list(const list<T>& lt);

(2)使用演示

// 1. constructor
void test1()
{// 1. 默认构造函数list<int> lt1;cout << "lt1.size: " << lt1.size() << endl << endl;// 2. 指定个数和初始值list<int> lt2(5, 1);cout << "lt2.size: " << lt2.size() << endl;cout << "lt2: ";for (const auto& e : lt2)cout << e << " ";cout << endl << endl;// 3. 迭代器构造函数vector<int> vt_i;for (int i = 1; i < 5; ++i)vt_i.push_back(i);list<int> lt3(vt_i.begin(), vt_i.end());cout << "lt3.size: " << lt3.size() << endl;cout << "lt3: ";for (const auto& e : lt3)cout << e << " ";cout << endl << endl;// 4. 拷贝构造函数list<int> lt4(lt3);cout << "lt4.size: " << lt4.size() << endl;cout << "lt4: ";for (const auto& e : lt4)cout << e << " ";cout << endl << endl;
}

(3)运行结果
在这里插入图片描述

2. 迭代器(iterator)

  下面介绍 list 常用的四个迭代器。反向迭代器参考正向迭代器的用法。

(1)函数声明

// 1. 普通迭代器
iterator begin();
iterator end();
// 2. const 迭代器
const_iterator begin() const;
const_iterator end() const;
// 3. 反向迭代器
reverse_iterator rbegin();
reverse_iterator rend();
// 4. const 反向迭代器
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;

(2)使用演示

// 2. 迭代器
void test2()
{list<int> lt1;for (int i = 1; i < 10; ++i)lt1.push_back(i);// 1. 正向迭代器遍历list<int>::iterator it = lt1.begin();while (it != lt1.end()){cout << *it << " ";++it;}cout << endl;// 2. 反向迭代器遍历list<int>::reverse_iterator rit = lt1.rbegin();while (rit != lt1.rend()){cout << *rit << " ";++rit;}cout << endl;
}

(3)运行结果
在这里插入图片描述

3. 容量、修改和访问(capacity 、modify and access)

  下面分别介绍 list 的 2 个与容量有关的接口、2 个与访问有关的接口,8 个与修改有关的接口。

(1)函数声明
  下面的 T 是模版中的类型参数。

// 1. capacity
size_t size() const;
bool empty() const;// 2. access
T& front();
T& back();// 3. modify
void push_front(const T& value);
void push_back(const T& value);
void pop_front();
void pop_back();
iterator insert(iterator pos, const T& value);  // 在 pos 位置前插入
iterator erase(iterator pos);  // 删除 pos 位置

(2)使用演示

// 3. capacity、access and modify
void test3()
{// 1. capacitylist<int> lt1;if (lt1.empty()){cout << "lt1 is empty.\n";}for (int i = 1; i < 10; ++i)lt1.push_back(i);cout << "lt1.size: " << lt1.size() << endl << endl;// 2. accesscout << "lt1.front: " << lt1.front() << endl;cout << "li1.back: " << lt1.back() << endl;// 3. modifylist<int> lt2;// 插入lt2.push_back(1);lt2.push_front(2);// 打印for (const auto& e : lt2)cout << e << " ";cout << endl;// 插入lt2.insert(lt2.begin(), 10);lt2.insert(lt2.end(), 99);// 打印for (const auto& e : lt2)cout << e << " ";cout << endl;// 删除lt2.pop_back();lt2.pop_front();// 打印for (const auto& e : lt2)cout << e << " ";cout << endl;// 删除lt2.erase(lt2.begin());lt2.erase(--lt2.end());// 打印for (const auto& e : lt2)cout << e << " ";cout << endl;
}

(3)运行结果
在这里插入图片描述

http://www.dtcms.com/a/563772.html

相关文章:

  • 成都网站关键排名免费做电子书的网站
  • 怎样做的英文网站长沙整站优化
  • 网站开发手机验证码网站右键禁止
  • 设计网站的软件蓟县网站建设公司
  • 网站建设谈判长春网络哪家好
  • 张槎建网站网页游戏手机怎么玩
  • ecetc商务网站建设工程师网页制作模板菜鸟
  • 高端文化网站单位 内网网站建设
  • 做国外零售的话是在什么网站开店可以制作图片的手机软件
  • wordpress 5.1.1漏洞公众号关键词排名优化
  • 西安建网站公司免费分销平台有哪些
  • 河北中石化建设网站青岛新公司网站建设推广
  • 在阿里巴巴上做网站需要什么条件室内设计学校在哪里
  • 企业网站推广费用wordpress 金币
  • 高端品牌网站建设(杭州)怎么推广平台
  • 中国建设招标网站中标公告网站搭建策略与方法是什么
  • 设计得很好的企业网站聚名网是干什么的有风险的
  • 网站备案期间如何wordpress神主题
  • 工信部网站备案时间wordpress html音乐
  • html5中国网站欣赏网站安全架构
  • 哪些网站是动态的攀枝花网站网站建设
  • 高清网站seo学校网站开发与实现的解决思路
  • 晋城市建设局 网站网站建设评比标准
  • 阿里云linux主机如何添加2个网站南宁刚刚发生的事
  • 有经验的郑州网站建设关键词优化价格表
  • 分析建设网站的可行性分析整站优化案例
  • 上海网站建设千元漂亮自己创建小程序
  • 手表网站哪家好wordpress分类展示插件
  • 对网站的界面设计分析哪个网站做五金冲压的
  • 合肥做网站怎么样企业网站开发 宁波网络公司