Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2084575
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: C/C++

2008-09-26 14:51:01

List

Lists are a kind of sequence containers. As such, their elements are ordered following a linear sequence.

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 by the association to each element of a link to the element preceding it and a link to the element following it.

This provides the following advantages to list containers:

  • Efficient insertion and removal of elements anywhere in the container (constant time).
  • Efficient moving elements and block of elements within the container or even between different containers (constant time).
  • Iterating over the elements in forward or reverse order (linear time).

Compared to other base standard sequence containers (s and s), lists perform generally better in inserting, extracting and moving elements in any position within the container, and therefore also in algorithms that make intensive use of these, like sorting algorithms.

The main drawback of s compared to these other sequence containers is that they lack direct access to the elements by their position; For example, to access the sixth element in a one has to iterate from a known position (like the beginning or the end) to that position, which takes linear time in the distance between these. They also consume some extra memory to keep the linking information associated to each element (which may be an important factor for large lists of small-sized elements).

Storage is handled automatically by the class, allowing lists to be expanded and contracted as needed.

In their implementation in the C++ Standard Template Library lists take two template parameters:

template < class T, class Allocator = allocator > class list;
Where the template parameters have the following meanings:
  • T: Type of the elements.
  • Allocator: Type of the allocator object used to define the storage allocation model. By default, the allocator class template for type T is used, which defines the simplest memory allocation model and is value-independent.
In the reference for the list member functions, these same names are assumed for the template parameters.

Member functions

Construct list (public member function)
List destructor (public member function)
Copy container content (public member function)

Iterators:

Return iterator to beginning (public member function)
Return iterator to end (public member function)
Return reverse iterator to reverse beginning (public member function)
Return reverse iterator to reverse end (public member function)

Capacity:

Test whether container is empty (public member function)
Return size (public member function)
Return maximum size (public member function)
Change size (public member function)

Element access:

Access first element (public member function)
Access last element (public member function)

Modifiers:

Assign new content to container (public member function)
Insert element at beginning (public member function)
Delete first element (public member function)
Add element at the end (public member function)
Delete last element (public member function)
Insert elements (public member function)
Erase elements (public member function)
Swap content (public member function)
Clear content (public member function)

Operations:

Move elements from list to list (public member function)
Remove elements with specific value (public member function)
Remove elements fulfilling condition (public member function template)
Remove duplicate values (member function)
Merge sorted lists (public member function)
Sort elements in container (public member function)
Reverse the order of elements (public member function)

Allocator:

Get allocator (public member function)

Member types

of template > class list;
member typedefinition
referenceAllocator::reference
const_referenceAllocator::const_reference
iteratorBidirectional iterator
const_iteratorConstant bidirectional iterator
size_typeUnsigned integral type (usually same as )
difference_typeSigned integral type (usually same as )
value_typeT
allocator_typeAllocator
pointerAllocator::pointer
const_pointerAllocator::const_pointer
reverse_iteratorreverse_iterator
const_reverse_iteratorreverse_iterator

阅读(1044) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~