Advertisement
vitormartinotti

Aula STL

Oct 3rd, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<set>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.     //---Vector---
  8.     //vector<tipo> nome;
  9.     /*
  10.     vector<int> v;
  11.     printf("%d\n", v.size());
  12.     v.push_back(5);
  13.     printf("%d\n", v.size());
  14.     printf("%d\n", v[0]);
  15.     v.pop_back();
  16.     printf("%d\n", v.size());
  17.     v.push_back(1);
  18.     v.push_back(2);
  19.     v.push_back(3);
  20.     v.push_back(4);
  21.     v.push_back(5);
  22.     for(int i = 0; i < v.size(); i++)
  23.         printf("%d\n", v[i]);
  24.     v.erase();
  25.     v.begin(); == &v[0];
  26.     v.end(); == &v[4];
  27.     v.resize(10, 1);
  28.     */
  29.    
  30.     //---Set---
  31.     //Set é um vetor sempre ordenado que não repete elementos.
  32.  
  33.     set<int> s; //É um conjunto ordenado onde os elementos não se reprtem
  34.  
  35.     s.insert(1);// s = {1}
  36.     s.insert(3);// s = {1,3}
  37.     s.insert(2);// s = {1,2,3}
  38.     s.insert(2);// s = {1,2,3}
  39.  
  40.     s.erase(1);//Apaga o elemento do set
  41.  
  42.     if(s.find(3) != s.end()){cout<<"contem 3" << endl;}
  43.  
  44.     set<int>:: iterator it;
  45.     for(it = s.begin(); it != s.end(); it++){
  46.         printf("%d\n", *it);
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement