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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...