list.front();

//返回第一个元素

list.back();

//返回最后一个元素

 1 #include <iostream>
2 #include <list>
3
4 using namespace std;
5
6 int main()
7 {
8 int num[] = { 111,222,333,444,555 };
9 list<int> listInt(num, num + size(num));
10
11 int iFront = listInt.front();
12 int iBack = listInt.back();
13
14 cout << "iFront的值为:" << iFront << endl;
15 cout << "iBack的值为:" << iBack << endl;
16
17 cout << "修改前遍历 listInt:";
18 for (list<int>::iterator it = listInt.begin(); it != listInt.end(); it++)
19 {
20 cout << *it << " ";
21 }
22 cout << endl;
23
24 listInt.front() = 0;
25 listInt.back() = 666;
26
27 cout << "修改后遍历 listInt:";
28 for (list<int>::iterator it = listInt.begin(); it != listInt.end(); it++)
29 {
30 cout << *it << " ";
31 }
32 cout << endl;
33
34 return 0;
35 }

打印结果:

=======================================================================================================================

最新文章

  1. spring bean的生命周期
  2. [UWP]涨姿势UWP源码——RSS feed的获取和解析
  3. bootstrap-datepicker的使用
  4. Mac 安装mysql
  5. 亲们! 首次见面! 带来不适!多多见谅!---------&gt;&gt;Bank系统
  6. 幂运算(codevs 2541)
  7. php发送ssl邮件
  8. addClass 函数
  9. ubuntu OPENCV移植
  10. Elasticsearch和mysql数据同步(elasticsearch-jdbc)
  11. 初次使用nodejs的问题
  12. 听说你又一次放弃了Dagger2,来听老夫说道说道
  13. Spark初步 从wordcount开始
  14. dump文件解析之探索.Net的内存
  15. Web版记账本开发记录(二)开发过程遇到的问题小结1 对数据库的区间查询
  16. 关于php下的ajax赋值传值的调试
  17. 如何从应用直接跳转AppStore 电话 短信 邮件
  18. Java8 (Function,Consumer,Predicate,Supplier)详解
  19. The last time the sprint(最后一个冲刺)
  20. eclipse如何设置编译后target目录不提交svn服务器

热门文章

  1. cosbench使用方法
  2. DockerPush
  3. kali 系列学习09-Kali-linux设置ProxyChains
  4. 「CEOI2013」Board
  5. sharding事务。
  6. 红黑树、TreeMap、TreeSet
  7. Django匆匆一眼却解答了多年疑惑
  8. 20191012_WMI中可以看到有打印机, 设备管理器中没有
  9. 初学者值得拥有Hadoop单机模式环境搭建
  10. lcm的和(莫比乌斯反演)