c++ STL 007 容器(list)

list

模版原型:
template < class T, class Alloc = allocator > class list;

是一个双向链表

Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions.

List containers are implemented as doubly-linked lists; Doubly linked lists can store each of the elements they contain in different and unrelated storage locations. The ordering is kept internally by the association to each element of a link to the element preceding it and a link to the element following it.

They are very similar to forward_list: The main difference being that forward_list objects are single-linked lists, and thus they can only be iterated forwards, in exchange for being somewhat smaller and more efficient.

成员

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

示例

#include <iostream>
#include <list>

using namespace std;
int main ()
{
 /**
基本构造函数
*/
  list<int> first;                                // empty list of ints
  list<int> second (4,100);                       // 4 ints with value 100
  list<int> third (second.begin(),second.end());  // iterating through second
  list<int> fourth (third);                       // a copy of third
  int myints[] = {16,2,77,29};
  list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

  cout << "The contents of fifth are: ";
  for (list<int>::iterator it = fifth.begin(); it != fifth.end(); it++){
   cout << *it << ' ';
  }
  cout << endl;
	/**
		迭代器功能begin,end,rbegin,rend,cbegin,cend,crbegin,crend使用是stl容器中通用的功能,可以参考vector内容
		empty 是否为空列表
		size 列表尺寸
		max_size 当前环境可存档最大元素个数
		front,back 返回第一个、最后一个元素的引用
		back与end区别: 返回值不同,一个是引用,一个是迭代器。
			Returns a reference to the last element in the list container.
			Unlike member list::end, which returns an iterator just past this element, 
			this function returns a direct reference.
	*/
//assign Assign new content to container
//Assigns new contents to the list container, replacing its current contents, and //modifying its size accordingly.


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值