Fixed grammar, among other things. (#27130)

Since `#include <bits/stdc++.h>` is not a part of the C++ Standard, it was changed to more appropriate headers.
Also fixed the grammatical errors here.
Added a few helpful links.
This commit is contained in:
Nischay Hegde
2019-02-18 03:42:48 +05:30
committed by Manish Giri
parent 2e388035ca
commit c2e6329296

View File

@ -3,7 +3,7 @@ title: C++ STL Sets
--- ---
## Introduction of sets in C++ STL library ## Introduction of sets in C++ STL library
Sets are a type of associative containers in which each element has to be unique.The value of the element cannot be modified once it is added to the set, though it is possible to remove and add the modified value of that element. They are implemented using red-black tree. Sets are a type of associative container in which each element has to be unique. The value of the element cannot be modified once it is added to the set, though it is possible to remove and add the modified value of that element. They are implemented using [red-black tree](https://guide.freecodecamp.org/algorithms/red-black-trees/).
## Benefits of using sets ## Benefits of using sets
1. It stores only unique values. 1. It stores only unique values.
@ -13,8 +13,11 @@ Sets are a type of associative containers in which each element has to be unique
Example: Example:
```c++ ```c++
#include<bits/stdc++.h> #include<iostream>
using namespace std; #include <set>
using std::set;
using std::cout;
using std::endl;
int main() int main()
{ {
set <int> s; set <int> s;
@ -25,13 +28,14 @@ int main()
s.insert(2); //inserting same element 2 s.insert(2); //inserting same element 2
s.insert(6); s.insert(6);
for(auto i:s) for(auto i:s)
cout<<i<<" "; cout << i << " ";
cout<<s.size()<<endl; //gives the size of set cout << s.size() << endl; //gives the size of set
s.erase(5); // erasing element 5 from set s s.erase(5); // erasing element 5 from set s
return 0; return 0;
} }
``` ```
[Try this code out yourself!](https://wandbox.org/permlink/XIFK4d9suQdGniFm)
Creating a set object Creating a set object
```c++ ```c++
@ -46,8 +50,8 @@ s.insert(value_to_be_inserted);
Accessing set elements Accessing set elements
```c++ ```c++
set <int>::iterator it; set <int>::iterator it;
for(it=s.begin(); it!=s.end(); ++it) for(it = s.begin(); it != s.end(); ++it)
cout<<*it; cout << *it;
``` ```