If there is any difference between it1 and it2?
std::set<sometype> s; auto it1 = std::inserter(s, s.begin()); auto it2 = std::inserter(s, s.end());
Its time complexity is O(logN) where N is the size of the set. insert(): insert a new element. Its time complexity is O(logN) where N is the size of the set. size(): Returns the size of the set or the number of elements in the set.
set insert() function in C++ STL Return Value: The function returns an iterator pointing to the inserted element in the container.
insert() function is an inbuilt function in C++ STL, which is defined in <set> header file. This function is used to insert elements in the set container. when we insert the element the size of the container is increased by the number of the elements inserted.
The vector::insert() function in C++ Basically, the vector::insert() function from the STL in C++ is used to insert elements or values into a vector container. In general, the function returns an iterator pointing to the first of the inserted elements.
In practice, not much. If you're inserting a large number of already in order elements into an empty set
, the second will be somewhat faster, but that's about it. std::insert_iterator
calls insert
with the iterator; std::set
interprets it as a hint, and inserts in constant time (rather than lg n) if the insertion is immediately before the hint. (Actually, if the set
is empty, I think both will do exactly the same thing.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With