Implementation of Vector in c++

Just like arrays, vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements, and just as efficiently as in arrays. But unlike arrays, their size can change dynamically, with their storage being handled automatically by the container.

Screenshot : 


Code :


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    int t;
    vector<int> a;
    for(int i=0;i<6;i++)
    {
        int t;
        cin>>t;
        a.push_back(t);
    }
    if(a.empty())
    {
        cout<<"Vector is empty"<<endl;
        return 0;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<6;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\nThe size of vector is "<<a.size();
    return 0;
}

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank String Reduction Solution

Bit Stuffing Code Implementation in Java