You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b8734c5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: STL/set.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,28 @@ The often used operations in set are :
54
54
return 0;
55
55
}
56
56
```
57
-
Here you can see when we tried to insert 45 for the second time it was not inserted into the set. You can also insert variables which are taken from the user.
57
+
Here you can see when we tried to insert 45 for the second time it was not inserted into the set. You can also insert variables which are taken from the user. You can do that using a varible. See the code below or better understanding:
58
+
```cpp
59
+
#include <iostream>
60
+
#include <set>
61
+
62
+
using namespace std;
63
+
64
+
int main(){
65
+
66
+
set < int > MySet; // Declaring MySet
67
+
int x; // variable to take input
68
+
int n; // how many number you want to insert
69
+
70
+
for(int i = 0 ; i < n ; i++)
71
+
{
72
+
cin >> x;
73
+
Myset.insert(x); // inserting x into the MySet
74
+
}
75
+
76
+
return 0;
77
+
}
78
+
```
58
79
2.**ITERATOR :** Iterators are used to point out an element in the set as well as any other container in STL. [You can check this link to know more about iterators](https://definecoder.github.io/STL/iterator). Iterators are very important to access any element in the set. Lets see the list of the iterators for set and the code:
59
80
60
81
| Function | Work of the function |
@@ -139,7 +160,7 @@ The often used operations in set are :
139
160
```
140
161
141
162
3.**PRINTING A SET :** Printing of a set can be done in two ways. First one is using iterator and the second one is using C++11 short cut feature. We will include both here. Lets see:
142
-
-_**Using Iterator**_ : As you know iterator is a poiunter for the STL datatype or containers, It is very useful to access the elements in a set. First of all you need to declare an iterator of the type of the set that you want to work with. Then you have to iterate through the set using that iterator that you declared. Lest see the code for better understanding.
163
+
-_**Using Iterator**_ : As you know iterator is a pointer for the STL datatype or containers, It is very useful to access the elements in a set. First of all you need to declare an iterator of the type of the set that you want to work with. Then you have to iterate through the set using that iterator that you declared. Lest see the code for better understanding.
0 commit comments