Advertisement
r1411

Vector и List

Jun 16th, 2021
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. Vector:
  2.     Способы задания:
  3.         vector<int> a;              // Пустой вектор
  4.         vector<int> a(100);         // [0, 0, ..., 0] x100
  5.         vector<int> a(100, -3);     // [-3, -3, ..., -3] x100
  6.         vector<int> a = {1, 2, 3};  // [1, 2, 3] x100
  7.         vector<int> a(3, 5);        // [5, 5, 5]
  8.        
  9.         int b[3] = {-2, 4, 3};
  10.         vector<int> a(b, b+3);
  11.  
  12.     Взаимодействие:
  13.         a[0] = 2;   //Нулевой элемент приравнять к 2
  14.         v1 = v2;    // Записать копию v1 в v2
  15.         for(vector<int>::iterator it = v1.begin(); it != a.end(); it++)
  16.             cout << *it;
  17.        
  18.     Методы:
  19.         int size()
  20.         bool empty()
  21.         void push_back(int x) / push_front(int x)
  22.         void insert(iterator pos, int x)
  23.         void erase(iterator pos) / erase(iterator posStart, iterator posEnd)
  24.         int front(), back() - Первый / Последний элемент
  25.         void assign({int}) - Заменить значения вектора на значения массива
  26.         void clear()
  27.  
  28. List:
  29.     Способы задания:
  30.         list<int> b             // Пустой список
  31.         list<int> b(5)          // [0, 0, 0, 0, 0]
  32.         list<int> b(3, 5)       // [5, 5, 5]
  33.         list<int> b = {1, 2, 3} // [1, 2, 3]
  34.        
  35.     Взаимодействие:
  36.         b1 = b2;    // Записать копию v1 в v2
  37.         for(list<int>::iterator it = v1.begin(); it != a.end(); it++)
  38.             cout << *it;
  39.            
  40.     Методы:
  41.         int size()
  42.         bool empty()
  43.         void push_back(int x) / push_front(int x)
  44.         void insert(iterator pos, int x)
  45.         void erase(iterator pos) / erase(iterator posStart, iterator posEnd)
  46.         int front(), back() - Первый / Последний элемент
  47.         void assign({int}) - Заменить значения списка на значения массива
  48.         void clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement