Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. void wyswietl(vector <int> w)
  8. {
  9.     for (auto element : w)
  10.     {
  11.         cout << element << " ";
  12.     }
  13.  
  14.     /*for (int i = 0; i < w.size(); i++)
  15.     {
  16.         cout << w[i];
  17.     }*/
  18.     cout << endl;
  19. }
  20.  
  21. auto wypelnij(vector <int> w)
  22. {
  23.     int a;
  24.     for (int i = 0; i < 10; i++)
  25.     {
  26.         a = rand() % 20;
  27.         w.push_back(a);
  28.     }
  29.     return w;
  30. }
  31.  
  32. int main()
  33. {
  34.     srand(time(NULL));
  35.  
  36.  
  37.    //Deklaracja wektora
  38.  
  39.     vector <int> tab = {1,2,3,4,5,6,7,8,9};
  40.     vector <int> w;
  41.  
  42.     w = wypelnij(w);
  43.     wyswietl(w);
  44.  
  45.     //Wyswietalnie wektorow, tab.size() zwraca długosc wektora;
  46.  
  47.     tab.push_back(11); //dodaje na koncu wektora
  48.  
  49.  
  50.  
  51.     cout << endl << endl;
  52.  
  53.     cout << "Pierwszy element tablicy: " << w.front()<<endl; //Wyswietlanie pierwszego elementu
  54.     cout << " Ostatni element tablicy: " << w.back()<<endl;  //Wyswietlanie ostatniego elementu
  55.  
  56.     //tab.capacity();
  57.  
  58.  
  59.     //wyswietl(tab);
  60.  
  61.    
  62.  
  63.  
  64.     for (auto it = tab.begin(); it != tab.end(); ++it)  //it -> wspazuje ktora szufladka, begin wskazuje na pierwsza a end na za ostatnia.
  65.     {
  66.         cout << *it << "  ";
  67.     }
  68.     cout << endl << endl;
  69.     auto it = tab.begin() + 3; //wskazuje na element 4;
  70.     cout << *it<<endl;
  71.  
  72.     it = tab.begin();
  73.  
  74.     while (it != tab.end())
  75.     {
  76.         cout << *it++ << endl;
  77.     }
  78.  
  79.     cout << tab.front() << endl; //to nie iteratory !
  80.     cout << tab.back() << endl;
  81.  
  82.  
  83.  
  84.     tab.erase(tab.begin(), tab.begin()+5); //usuwa z zakresu
  85.  
  86.     for (auto it = tab.begin(); it != tab.end(); ++it)  //it -> wspazuje ktora szufladka, begin wskazuje na pierwsza a end na za ostatnia.
  87.     {
  88.         cout << *it << "  ";
  89.     }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement