
上QQ阅读APP看书,第一时间看更新
Code walkthrough
The following line declares a vector and initializes the vector with five elements:
vector<int> v = { 1, 5, 2, 4, 3 };
However, a vector also allows appending values to the end of the vector by using the vector::push_back<data_type>( value ) API. The sort() algorithm takes two random access iterators that represent a range of data that must be sorted. As the vector internally uses a built-in C/C++ array, just like the STL array container, a vector also supports random access iterators; hence the sort() function is a highly efficient algorithm whose runtime complexity is logarithmic, that is, O(N log2 (N)).