c plus STL and vector
2013-06-09 21:00
603 查看
STL(Standard Template Library)
STL is a c plus software library that influenced many parts of the C++ Standard Library.It provides four components, which called algorithms, containers, functors, and iterators. Such as HP STL、PJ STL、 SGI STL etc.
[b]STL has been built within your complier.And it has many different versions.http://write.blog.csdn.net/postedit
[/b]
In ANSI C ++ STL is organized into 13 header files:<algorithm>, <deque>, <functional><iterator>, <vector>, <list>, <map>, <memory>, <numeric>, <queue>, <set>, <stack>, <utility>.
And STL can be devided into 6 parts, including containers, iterators, allocators, adaptors, algorithms, functors.
Vector
Vector is considered a container, because of it can storge variable types objects just like containers.it can be used as a dynamic array . In order to use vector, we should include the header file
<vector>. And the vector is contained in the std namesapce,so if we intend to use the vector, we also need to limit the namespace as follows:
usingnamespace
std;
Of course,for using vector, there are some advantages but also some disadvantages.It can work fast for random access..., while slowly for insertion and deletion...
Constructors:
vector();
vector(int
initialcapacity,
int capacityIncrement);
vector(int initialcapacity);
For the first constructor, operator will manage the vector automatically.but for the latter two constructors, vector will be initialized with the
fixed capacity. and when the capacity is not enough to store the data, the vector' capasity will be increased with the size of
capacityincrement.
define:
vector<type>
vector_name;
member functions:
assign(beg, end);
assign the data of the region between beg and end to c.
assgin(n, elem);
assigin n datas to c.
at(idx);
return the data of index idx,if cross the border, throw an exception :out_of_range.
back();
return the last data without check if the data exist.
begin();
return the firt address of the iterator.
capacity();
return the number of the datas that be stored in capacity.
clear();
remove all datas from the capacity.
empty();
check if the capacity is empty.
end();
refer to the next of the last data, which is not exist.
erase(pos);
delete the data at position pos,and return the address of the next data.
erase(beg,
end);
delete datas of the region between beg and end, and return the address of the next data.
front();
return the first data.
get_allocator();
use the copy constructor and return a copy.
insert(pos,
elem);
insert an element at the position pos, and return the address of the new data.
insert(pos,
n, elem);
insert n datas at the position, and without return value.
max_size();
return the number of the maximum datas.
pop_back();
delete the last data.
push_back(elem);
insert an element to the end of the datas.
rbegin();
return the first data of an reverse queue.
rend();
refer to the next address of the last data in an reverse queue.
resize(num);
resize the length of the queue.
reserve();
reserve some capacitys.
size();
return the number of the datas in capacity.
STL is a c plus software library that influenced many parts of the C++ Standard Library.It provides four components, which called algorithms, containers, functors, and iterators. Such as HP STL、PJ STL、 SGI STL etc.
[b]STL has been built within your complier.And it has many different versions.http://write.blog.csdn.net/postedit
[/b]
In ANSI C ++ STL is organized into 13 header files:<algorithm>, <deque>, <functional><iterator>, <vector>, <list>, <map>, <memory>, <numeric>, <queue>, <set>, <stack>, <utility>.
And STL can be devided into 6 parts, including containers, iterators, allocators, adaptors, algorithms, functors.
Vector
Vector is considered a container, because of it can storge variable types objects just like containers.it can be used as a dynamic array . In order to use vector, we should include the header file
<vector>. And the vector is contained in the std namesapce,so if we intend to use the vector, we also need to limit the namespace as follows:
usingnamespace
std;
Of course,for using vector, there are some advantages but also some disadvantages.It can work fast for random access..., while slowly for insertion and deletion...
Constructors:
vector();
vector(int
initialcapacity,
int capacityIncrement);
vector(int initialcapacity);
For the first constructor, operator will manage the vector automatically.but for the latter two constructors, vector will be initialized with the
fixed capacity. and when the capacity is not enough to store the data, the vector' capasity will be increased with the size of
capacityincrement.
define:
vector<type>
vector_name;
member functions:
assign(beg, end);
assign the data of the region between beg and end to c.
assgin(n, elem);
assigin n datas to c.
at(idx);
return the data of index idx,if cross the border, throw an exception :out_of_range.
back();
return the last data without check if the data exist.
begin();
return the firt address of the iterator.
capacity();
return the number of the datas that be stored in capacity.
clear();
remove all datas from the capacity.
empty();
check if the capacity is empty.
end();
refer to the next of the last data, which is not exist.
erase(pos);
delete the data at position pos,and return the address of the next data.
erase(beg,
end);
delete datas of the region between beg and end, and return the address of the next data.
front();
return the first data.
get_allocator();
use the copy constructor and return a copy.
insert(pos,
elem);
insert an element at the position pos, and return the address of the new data.
insert(pos,
n, elem);
insert n datas at the position, and without return value.
max_size();
return the number of the maximum datas.
pop_back();
delete the last data.
push_back(elem);
insert an element to the end of the datas.
rbegin();
return the first data of an reverse queue.
rend();
refer to the next address of the last data in an reverse queue.
resize(num);
resize the length of the queue.
reserve();
reserve some capacitys.
size();
return the number of the datas in capacity.
相关文章推荐
- STL vector usage tips and problems
- 【CodeForces】501B - Misha and Changing Handles(STL - string & vector & pair)
- (STL之vector)spoj-Ada and List(易)
- STL的Vector, List and Deque
- cf C. Wilbur and Points (STL_vector)
- STL vector find and sort vector的查找和排序
- STL运用集合!(vector,map,list and so on)!!
- stl list vector and deque
- Sample of STL(Vector):begin and rbegin
- 你怎么就一根筋呢? STL之vector and string用还是不用
- C Primer Plus. Fifth Edition 翻译Chapter 3 数据和C (Data and C)第一部分
- STL源码分析之vector容器
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- 在STL中基本容器有: string、vector、list、deque、set、map
- STL中vector, Map, Set的实现原理
- C++ 标准库类型-String,Vector and Bitset
- Difference between ArrayList and Vector in Java
- 今日学习札记——STL常用容器:vector、list、set和multiset、map和multimap(11.17)
- STL 笔记: deque vector string
- STL学习----入门(1)[Vector]