STL排序查找 | Edit | ||
STL sort
sort(arr+n1, arr+n2, sortMethod() );
struct sortMethod {
bool operator( const int & a1, const int & a2)
{
return a1 < a2;
}
}
STL search
binary_search(arr+n1, arr+n2, val, sortMethod);
T* lower_bound(arr+n1, arr+n2, val, sortMethod);
find from first to the last, arr[n] >= val
T* upper_bound
|
|||
平衡二叉树multiset,map | Edit | 2021-12-31 | |
平衡二叉树结构,时间复杂度都是log(n)
multiset, set, multimap, map
multiset<T> st;
insert, find, erase
lower_bound, upper_bound
map<int, string> m;
m.insert(map<int, string>::value_type(num, str));
map<int, string>::iterator rec = m.begin();
rec = m.find(key) ;
if(rec == m.end()) {}
for( ; rec != m.end(); rec++)
|