Pages

Saturday, April 26, 2025

Vector Implementation in Memory in C++

#include <iostream>

#include <vector>

using namespace std;


int main()

{

    vector<int> vec;

    cout << "size : " << vec.size() << endl;

    cout << "capacity : " << vec.capacity() << endl;

       

    

    

    vec.push_back(4); // changes vec size to 4

    cout << "size : " << vec.size() << endl;

    cout << "capacity : " << vec.capacity() << endl; // 8 (double of 4)

    

    vec.pop_back(); // size resets

    cout << "size : " << vec.size() << endl;

    cout << "capacity : " << vec.capacity() << endl;

    return 0;

    

}

No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...