Lecture 6
Lecture 6
Greetings, dear students. I hope you are all alright and well <3 today we are going to discuss 3
different collection types, namely: set, map and stack. Let’s start with Set.
Sets are a type of associative container in which each element has to be unique because the
value of the element identifies it. Set saves its values sorting in ascending order by default.
1. set <data_type> set_name; // syntax of declaring set variable
2. set<int> val; // creating a set of type integer
3. set<int, greater<int> > val2; // creating a set of type integer with decreasing order
Adding values to set variable:
1. set<int> val = {6, 10, 5, 1}; // creating a set of type int and assigning values to it
2. val.insert(8); // adding values later with built-in function of set
Properties of Set