← Back to Home

STL Data Structures & Iterator Mechanics

Project Overview

This core systems project evaluates data container mechanics and pointer indexing strategies implemented via the C++ Standard Template Library (STL). The application configures dynamic memory sequences using std::vector frameworks and ordered associative key-value records using std::map structures, exercising direct iterator traversals, search queries, linear element erasures, and quick-sort sorting routines.

Algorithmic Operations Demonstrated

The codebase programmatically updates memory data layers across a series of structured milestones:

Core C++ Implementation Source Code

Below is the explicit program structure compiling the full tracking algorithms and operational loops:

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

// Print function using iterators to print the data
void print(vector<int>& v_data, map<char,int>& m_data)
{
    cout << "vector elements are" << endl;
    for(auto it=v_data.begin(); it!=v_data.end(); it++)
        cout << *it << " ";
    cout << endl;
    
    cout << "map elements are" << endl;
    for (auto it = m_data.begin(); it != m_data.end(); it++)
        cout << it->first << " " << it->second << " ";
    cout << endl;
}

void sortElementsVec(vector<int>& v_data) {
    sort(v_data.begin(), v_data.end());
}

// Driver code done with vectors
int main()
{
    vector<int> vecOfint;
    map<char, int> mapOfInt;

    vecOfint.push_back(10);
    vecOfint.push_back(1);
    vecOfint.push_back(20);
    vecOfint.push_back(2);
    vecOfint.push_back(30);
    vecOfint.push_back(3);
    vecOfint.push_back(40);
    vecOfint.push_back(4);
    vecOfint.push_back(50);
    vecOfint.push_back(5);
    
    mapOfInt.insert(std::pair<char, int>('A', 65));
    mapOfInt.insert(std::pair<char, int>('B', 66));
    mapOfInt.insert(std::pair<char, int>('C', 67));
    mapOfInt.insert(std::pair<char, int>('D', 68));
    mapOfInt.insert(std::pair<char, int>('E', 69));
    mapOfInt.insert(std::pair<char, int>('F', 70));
    mapOfInt.insert(std::pair<char, int>('G', 71));
    mapOfInt.insert(std::pair<char, int>('H', 72));
    mapOfInt.insert(std::pair<char, int>('I', 73));
    mapOfInt.insert(std::pair<char, int>('J', 74));
    
    // print function called after adding 10 elements
    print(vecOfint, mapOfInt);

    vecOfint.push_back(60);
    vecOfint.push_back(6);
    vecOfint.push_back(70);
    vecOfint.push_back(7);
    vecOfint.push_back(80);
    vecOfint.push_back(8);
    vecOfint.push_back(90);
    vecOfint.push_back(9);
    vecOfint.push_back(100);
    vecOfint.push_back(11);
    
    mapOfInt.insert(std::pair<char, int>('K', 75));
    mapOfInt.insert(std::pair<char, int>('L', 76));
    mapOfInt.insert(std::pair<char, int>('M', 77));
    mapOfInt.insert(std::pair<char, int>('N', 78));
    mapOfInt.insert(std::pair<char, int>('O', 79));
    mapOfInt.insert(std::pair<char, int>('P', 80));
    mapOfInt.insert(std::pair<char, int>('Q', 81));
    mapOfInt.insert(std::pair<char, int>('R', 82));
    mapOfInt.insert(std::pair<char, int>('S', 83));
    mapOfInt.insert(std::pair<char, int>('T', 84));

    // print function called again after adding 10 more elements
    print(vecOfint, mapOfInt);
    
    // erase is vector function for deleting
    vector<int>::iterator it = find(vecOfint.begin(), vecOfint.end(), 20);
    vecOfint.erase(it);
    it = find(vecOfint.begin(), vecOfint.end(), 30);
    vecOfint.erase(it);
    it = find(vecOfint.begin(), vecOfint.end(), 40);
    vecOfint.erase(it);
    it = find(vecOfint.begin(), vecOfint.end(), 50);
    vecOfint.erase(it);
    it = find(vecOfint.begin(), vecOfint.end(), 60);
    vecOfint.erase(it);

    // sort the vector
    sortElementsVec(vecOfint);
    
    // final call after deleting 5 elements
    print(vecOfint, mapOfInt);
    return 0;
}

Program Execution Output

The following block captures the step-by-step console readout stream produced after performing sequential container array push updates, specific variable cancellations, and pointer sorting adjustments:

vector elements are 10 1 20 2 30 3 40 4 50 5 map elements are A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 vector elements are 10 1 20 2 30 3 40 4 50 5 60 6 70 7 80 8 90 9 100 11 map elements are A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79 P 80 Q 81 R 82 S 83 T 84 vector elements are 1 2 3 4 5 6 7 8 9 10 11 70 80 90 100 map elements are A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79 P 80 Q 81 R 82 S 83 T 84 Program ended with exit code: 0

Data Mechanics Specifications