Sets in STL - C++


Hello coders, we welcome you to learn this concept.


Definition : Sets are associative container (Elements in associative containers are referenced by their key and not by their absolute position in the container) which contains sorted elements and each element of set has to be unique because the value is itself the key.

The value of the elements in a set cannot be modified once in the container, i.e. the elements are always constant. But they can be inserted or removed from the container. If you inserting an element more than once into the set then it's treated as single element (duplicates are not allowed ) .

Note: Whenever you are declaring a set do not forget to add #include<set> library.

Code:

Output:

Size of first set is 5

Size of second set is 5

Size of third set is 0

--------------------------Content of first set--------------------------

10 20 30 40 50

--------------------------Content of second set--------------------------

1 2 3 4 5 10 20 30 40 50

--------------------------Content of third set--------------------------

Algo Point

10 is an element of both set.

30 is an element of both set.

50 is an element of both set.

70 is not an element of both set.

90 is not an element of both set.

20 is present in the set.

Lower bound of 20 is 20

Lower bound of 60 is 70

Lower bound of 80 is 5

Upper bound of 30 is 40

--------------------------Content of first set--------------------------

20 30 40 50 70

--------------------------Content of second set--------------------------

1

--------------------------Content of third set--------------------------

Programmers Army


So that’s it for this article we will be coming up with our next article very soon till then keep learning, keep coding, keep reading and keep improving !!


Happy Coding 😊

By Programmers Army