Skip to content

Commit b8734c5

Browse files
authored
Added user input
1 parent 4cdfb58 commit b8734c5

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

‎STL/set.md‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,28 @@ The often used operations in set are :
5454
return 0;
5555
}
5656
```
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+
```
5879
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:
5980

6081
| Function | Work of the function |
@@ -139,7 +160,7 @@ The often used operations in set are :
139160
```
140161

141162
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.
143164

144165
```cpp
145166
#include <iostream>

0 commit comments

Comments
 (0)