vector operations in c 2b 2b

Solutions on MaxInterview for vector operations in c 2b 2b by the best coders in the world

showing results for - "vector operations in c 2b 2b"
Alan
23 May 2020
1#include <vector>
2
3int main() {
4  std::vector<int> v;
5  v.push_back(10); // v = [10];
6  v.push_back(20); // v = [10, 20];
7  
8  v.pop_back(); // v = [10];
9  v.push_back(30); // v = [10, 30];
10  
11  auto it = v.begin();
12  int x = *it; // x = 10;
13  ++it;
14  int y = *it; // y = 30
15  ++it;
16  bool is_end = it == v.end(); // is_end = true
17  
18  return 0;
19}
Moritz
11 Apr 2017
1#include <iostream>
2#include<vector>
3#include<algorithm>
4
5using namespace std;
6
7int main()
8{
9    int n;
10    cin>>n;
11    vector<int>vec(n);
12    for(int i=0;i<n;i++)
13    {
14        cin>>vec[i];
15    }
16    cout<<"----------"<<endl;
17    for(int i=0;i<n;i++)
18    {
19      cout<<vec[i]<<" ";
20    }
21    vec.push_back(100);
22    vec.push_back(200);
23    cout<<endl;
24    auto it=vec.begin();
25    vec.insert(it,3,1000);
26    for(vector<int>::iterator it1=vec.begin();it1!=vec.end();it1++)
27    {
28        cout<<*it1<<" ";
29    }
30    cout<<endl;
31    vector<int>vec2;
32    vec2.push_back(15);
33    vec2.push_back(25);
34    vec2.push_back(35);
35    vec.insert(it,vec2.begin(),vec2.end());
36    for(vector<int>::iterator it1=vec.begin();it1!=vec.end();it1++)
37    {
38        cout<<*it1<<" ";
39    }
40    cout<<endl;
41    vec.pop_back();
42    vec.pop_back();
43    for(vector<int>::iterator it1=vec.begin();it1!=vec.end();it1++)
44    {
45        cout<<*it1<<" ";
46    }
47    cout<<endl;
48    int k;
49    cin>>k;
50    cout<<endl;
51    vector<int>::iterator its=vec.begin()+k-1;
52    int s=vec.size();
53    cout<<s<<endl;
54    vec.erase(its);
55    for(vector<int>::iterator it1=vec.begin();it1!=vec.end();it1++)
56    {
57        cout<<*it1<<" ";
58    }
59    
60
61    return 0;
62}
63
queries leading to this page
function of vector typevecotr c 2b 2bvector operations in cppvector in c 2b 2b 2bc 2b 2b vector 2b 3dc 2b 2b vectorvector in c 2b 2bcpp vector classvector 2b vectorvector in c 2b 3fcpp std vectorvector in functions c 2b 2bvector c 2b 2b 7b 7dc 2b 2b reference vectorc 2b 2b std vectoroperation of vectors in c 2b 2bvector 5b 5d c 2b 2bvector c 2b 2b operationsvector operations c 2b 2bvector vector cppvector c 2b 2bc 2b 2b com vectorc 2b 2b vector apivector functions in c 2b 2bdefine vectorstd 3a 3avectorvector function in c 2b 2bvector in cppc 2b 2b vectorvector 28 29 c 2b 2bvector in functions in c 2b 2bc 2b 2b vector 28 29vector c 2b 2b examplevector is c 2b 2bvector c 2b 2bvector c 2b 2b stlusing vectors c 2b 2b 2b 2b vector cppvector 3d vector c 2b 2bvector std c 2b 2boperation with vectors c 2b 2bvector 2b vector cppvector 2a cpp vector vector cppc 2b 2b make vector from arc 2b 2b vectorvector operations library c 2b 2bvector c 2b 2b 2bvector vector container class c 2b 2b referencemake a vector that cant be added to c 2b 2bvector 3d 3d c 2b 2bwhat is a c 2b 2b vectorc 2b 2b function vectorall vector operations c 2b 2bvector meaning c 2b 2bcpp vector 5b 5dc 2b 2b 2b vectorvector methodsc 2b 2b vector classcpp vectvector 3cll 3e cppstd 3a 3avector cpush front vector c 2b 2bvector array c 2b 2bstd vecctorvector in c 2b 2bwhat is c 2b 2b vectorc 2b 2b vector arrayvector syntax c 2b 2bc 2b vectorc 3d 2b vectorc 2b 2b vector vectorelement vector operations c 2b 2bvector in function c 2b 2bvector in cpp vector for class c 2b 2bstl vector vector c 2b 2bvector operationsc 2b 2b vector in c 24vector library c 2b 2bvector inc 2b 2bvector en c 2b 2bvector library c 2b 2b c 2b 2bc vectorsc 2b 2b vector explainedvector cppall vector functions c 2b 2b and o notationc 2b 2b stl vectordefine vector c 2b 2b 5cvector vector c 2b 2bvector vector c 2b 2bvector of vector cppvector in c 2b 2b 5cstd 3a 3a vectorvector cpp comc 2b 2b vector of listc 2b 2b vector 5b 5dvector c 3d 2blength of container class vector cppc 2b 2b vector 3d std 3a 3avector c 2b 2bstd vector c 2b 2bstd 3a 3avector cppstd vecotrreference to vector c 2b 2bc 2b 2b method vectorshould i use vector in c 2b 2bc 2b 2b std 3a 3avector 3cstd 3a 3avector 3ec 2b 3d vectorvector 3d 3d cppvector in c c 2b 2bvector std c 2b 2b vectorvector c 2b 2b 5coperations on vectors in c 2b 2bc vectorvector class c 2b 2bcpp std 3a 3avectomodifier vector class c 2b 2bvector c 2b 2b arrayvector definition c 2b 2boperations on vector in c 2b 2bvector c 2b 2bvector c 2b 2b referencec 2b 2b vector 28 29vector c 3d 2b 2bvector api c 2b 2bvector type c 2b 2bcpp vectorvector cplus c 2b 2b vectordefine vector c 2b 2bvector operations meansc 2b 2b vector 2a 2b vectorc 2b 2b vector librarycpp vectorsvector inc 2b 2bvector i cppvector 27 stdc 2b 2b what is a vectorvector in c 2b 3dcpp vectoresc 2b 2b vector syntaxvectors c 2b 2bc 2b 2b vector 3d vectorc 2b 2b std 3a 3avectorsubvector of a vector c 2b 2bstd vectorc 2b 2b vectorc 2b 2b vecotrc 2b 2b vector 2b vectorvector methodsc 2b 2b vector vector in c 2b 2bvector in cppwhat are vector in c 2b 2bvectors cppc 2b 2b vector of class objects reassignvector 26 c 2b 2bvector cppvector in c 2bvector operations in c 2b 2bvector in c 2b 2b operationsvector cplus plusvector methods c 2b 2bwhat are vectors c 2b 2bvector in c 2b 2b 27vector c 2bvector 2b 2bvector operations in c 2b 2b