Container Flashcards
(23 cards)
the library of pair
include<utility></utility>
pair declaration
pair<F, S> newPair (newPair is the pair’s name)
create a pair with the specified first and second values, and how to access them
make_pair() ; name’s pair.first, name’s pair.second
declare a pair playAttempts with an integer as the first element and a double as the second element
pair<int, double> playAttempts;
the library of list
include <list></list>
list declaration
list<T> newList;</T>
push_back()
adds an element to the end of the list
push_front()
adds an element to the front of the list
front
returns the front element of the list
back()
return the back element (last element) of the list
pop_back, pop_front
removes element from the end of the list, from the front of the list
remove
remove all the occurrences in the list
how to declare the iterator in the list
list<T>:: iterator iter;</T>
insert
insert(iteratorPosition, newElement) -> insert newElement into the list before the iteratorPosition
erase
erase(iteratorPosition) - removes a single element at iteratorPosition
erase(iteratorFirst, iteratorLast) - removes a range of elements from iteratorFirst(inclusive) to iteratorLast(exclusive)
emplace() function in Map
emplace function associates a key with specified value. If the key does not exist, the map is not updated.
how to update map entry
EX:
statePopulation.at(“CA”) = 39000
how to determine if the key exists in the map
count(key)
erase(key)
removes the map entry for the specified key if the key exists
clear()
removes all map entries
how to define function template
template<typename>
T TripleMin(T para1, T para2, T para3)</typename>
function template with multiple parameters
template<typename T1, typename T2>
ReturnType FunctionName(Parameters){
….
}
class template declaration
template<typename>
class TripleItem {</typename>
}
template<typename> T1
TripleItem<TheType>::</TheType></typename>