| Important functions| | Manipulation Algorithm | | String important functions | | Sets | | Maps |
- sort(arr,arr+n) : quick sort in (nlogn) ascending order.
- sort(arr,arr+n,greater()) : sort in descending order.
- sort(arr,arr+n, comparable) : sort accordingly.
bool comparable(int a, int b)
{
return a>b;
}
reverse(arr,arr+n);
*max_element(arr,arr+n);
*min_element(arr,arr+n);
accumulate(arr,arr+n,0) : 0 is to specify the initial value of sum
count(arr,arr+n);
find(arr,arr+n,pattern); return iterator to first match else vector.end() if not found
rotate(arr.begin(), arr.begin()+3, arr.end()); the element at 3rd position become the first after first rotate. rotate(arr.begin(), arr.end() + (arr.size() - 3), arr.end()); the element at 3rd position become the first after last 3rd rotate.
lower_bound(arr,arr+n,x);
upper_bound(arr,arr+n,x);
set_intersection(vec1.begin(),vect1.end(),vec2.begin(),vect2.end(), result.begin()) : store the common elements in result vector
set_union(vec1.begin(),vect1.end(),vec2.begin(),vect2.end(), result.begin()) : store the all elements in result vector
arr.erase(iteratorPosition) : erases the element at position +1 arr.erase(unique(arr.begin(),arr.end()), arr.end()) : erases the duplicate elements.
- next_permutation(arr,arr+n);
- prev_permutation(arr,arr+n);
- str.find_last_of("pattern") :returns substring index position of the match from the last
- str.find_first_of("pattern") : returns substring index position of the match from the beginning
- str.find("pattern"): return position of the patterns first match else return -1;
- str.substr(position) : return sub-string from that position to the last.
- str.substr(indexPosition, substringLength) : return sub-string from that position to the sub-string length specified.
set<int,greater> setName; : stores element in descending order. set.insert(10);
set setName(arr.begin(),arr.end())
setName.find(30) : return iterator position else return setName.end()
- setName.erase(value)
- setName.erase(arr.begin(),arr.end(), setName.find(30) )
setName.count(element) : // return 1 if present or 0 when not present.
- map<int,int> mapName;
- mapName.insert(pair<int,int>(10,40));
- itrPos->first : gives key
- itrPos->second : gives value
mapName.find(keyValue)->second = newValue;