Repository: TheAlgorithms/C-Plus-Plus
File: greedy_algorithms/gale_shapley.cpp (C++)

Code before:

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @namespace
 * @brief Functions for the Gale-Shapley Algorithm
 */
namespace stable_matching {
/**
 * @brief The main function that finds the stable matching between two sets of elements 
 * using the Gale-Shapley Algorithm.
 * @note This doesn't work on negative preferences. the preferences should be continuous integers starting from 
 * 0 to number of preferences - 1.
 * @param primary_preferences the preferences of the primary set should be a 2D vector
 * @param secondary_preferences the preferences of the secondary set should be a 2D vector
 * @returns matches the stable matching between the two sets
 */
std::vector<unsigned int> gale_shapley(const std::vector<std::vector<unsigned int>>& secondary_preferences, const std::vector<std::vector<unsigned int>>& primary_preferences) {
    unsigned int num_elements = secondary_preferences.size();
    std::vector<unsigned int> matches(num_elements, -1);
    std::vector<bool> is_free_primary(num_elements, true);
    std::vector<unsigned int> proposal_index(num_elements, 0); // Tracks the next secondary to propose for each primary

    while (true) {
        int free_primary_index = -1;

        // Find the next free primary
        for (unsigned int i = 0; i < num_elements; i++) {
            if (is_free_primary[i]) {
                free_primary_index = i;
                break;
            }
        }

        // If no free primary is found, break the loop
        if (free_primary_index == -1) break;

        // Get the next secondary to propose
        unsigned int secondary_to_propose = primary_preferences[free_primary_index][proposal_index[free_primary_index]];
        proposal_index[free_primary_index]++;

        // Get the current match of the secondary
        unsigned int current_match = matches[secondary_to_propose];

Review comment (suggestion):
Please use fixed width width integers like 
```cpp
std::uint32_t
```

Code after:

#include <iostream>   /// for std::u32int_t
#include <vector>     /// for std::vector
#include <algorithm>  /// for std::find
#include <cassert>    /// for assert

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @namespace
 * @brief Functions for the Gale-Shapley Algorithm
 */
namespace stable_matching {
/**
 * @brief The main function that finds the stable matching between two sets of elements 
 * using the Gale-Shapley Algorithm.
 * @note This doesn't work on negative preferences. the preferences should be continuous integers starting from 
 * 0 to number of preferences - 1.
 * @param primary_preferences the preferences of the primary set should be a 2D vector
 * @param secondary_preferences the preferences of the secondary set should be a 2D vector
 * @returns matches the stable matching between the two sets
 */
std::vector<std::uint32_t> gale_shapley(const std::vector<std::vector<std::uint32_t>>& secondary_preferences, const std::vector<std::vector<std::uint32_t>>& primary_preferences) {
    std::uint32_t num_elements = secondary_preferences.size();
    std::vector<std::uint32_t> matches(num_elements, -1);
    std::vector<bool> is_free_primary(num_elements, true);
    std::vector<std::uint32_t> proposal_index(num_elements, 0); // Tracks the next secondary to propose for each primary

    while (true) {
        int free_primary_index = -1;

        // Find the next free primary
        for (std::uint32_t i = 0; i < num_elements; i++) {
            if (is_free_primary[i]) {
                free_primary_index = i;
                break;
            }
        }

        // If no free primary is found, break the loop
        if (free_primary_index == -1) break;

        // Get the next secondary to propose
        std::uint32_t secondary_to_propose = primary_preferences[free_primary_index][proposal_index[free_primary_index]];
        proposal_index[free_primary_index]++;

        // Get the current match of the secondary
        std::uint32_t current_match = matches[secondary_to_propose];