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

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...