Set

Set Functions

 

set<int> myset;

myset.insert(7);

int arr[]= {5,10,15};
myset.insert(arr , arr+2);

//final : 7 , 5 , 10  (****15 is not included)

 

//1.) Advance

eg : set<string> s ;

s.insert("zunglee");
s.insert("bits");
s.insert("of");
s.insert("jarvis");

auto first = s.begin(); // get iterator to 1st element
std::advance(first, 1);     // advance by 1
std::cout << *first;        // first element

//2.) std::next

auto it = std::next(myset.begin(), 5);
std::cout << *it;



std::advance

modifies its argument
returns nothing
works on input iterators or better (or bi-directional iterators if a negative distance is given)
std::next

leaves its argument unmodified
returns a copy of the argument, advanced by the specified amount
works on forward iterators or better (or bi-directional iterators if a negative distance is given))

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback
1 year ago

[…] Data structure :vectorstringstackqueuemapheapset […]

error

Enjoy this blog? Please spread the word :)

1
0
Would love your thoughts, please comment.x
()
x