Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <time.h>
- using namespace std;
- void wyswietl(vector <int> w)
- {
- for (auto element : w)
- {
- cout << element << " ";
- }
- /*for (int i = 0; i < w.size(); i++)
- {
- cout << w[i];
- }*/
- cout << endl;
- }
- auto wypelnij(vector <int> w)
- {
- int a;
- for (int i = 0; i < 10; i++)
- {
- a = rand() % 20;
- w.push_back(a);
- }
- return w;
- }
- int main()
- {
- srand(time(NULL));
- //Deklaracja wektora
- vector <int> tab = {1,2,3,4,5,6,7,8,9};
- vector <int> w;
- w = wypelnij(w);
- wyswietl(w);
- //Wyswietalnie wektorow, tab.size() zwraca długosc wektora;
- tab.push_back(11); //dodaje na koncu wektora
- cout << endl << endl;
- cout << "Pierwszy element tablicy: " << w.front()<<endl; //Wyswietlanie pierwszego elementu
- cout << " Ostatni element tablicy: " << w.back()<<endl; //Wyswietlanie ostatniego elementu
- //tab.capacity();
- //wyswietl(tab);
- for (auto it = tab.begin(); it != tab.end(); ++it) //it -> wspazuje ktora szufladka, begin wskazuje na pierwsza a end na za ostatnia.
- {
- cout << *it << " ";
- }
- cout << endl << endl;
- auto it = tab.begin() + 3; //wskazuje na element 4;
- cout << *it<<endl;
- it = tab.begin();
- while (it != tab.end())
- {
- cout << *it++ << endl;
- }
- cout << tab.front() << endl; //to nie iteratory !
- cout << tab.back() << endl;
- tab.erase(tab.begin(), tab.begin()+5); //usuwa z zakresu
- for (auto it = tab.begin(); it != tab.end(); ++it) //it -> wspazuje ktora szufladka, begin wskazuje na pierwsza a end na za ostatnia.
- {
- cout << *it << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement