ronantakizawa/codereview-bench huggingface dataset:
Repository: TheAlgorithms/C-Plus-Plus
File: bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp (C++)

Code before:
}

}  // namespace bit_manipulation

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    // x = 4 return 8
    assert(bit_manipulation::next_higher_number(4) == 8);
    // x = 6 return 9
    assert(bit_manipulation::next_higher_number(6) == 9);
    // x = 13 return 14
    assert(bit_manipulation::next_higher_number(13) == 14);
    // x = 64 return 128
    assert(bit_manipulation::next_higher_number(64) == 128);
    // x = 15 return 23
    assert(bit_manipulation::next_higher_number(15) == 23);
    // x= 32 return 64
    assert(bit_manipulation::next_higher_number(32) == 64);
    // x = 97 return 98
    assert(bit_manipulation::next_higher_number(97) == 98);
    // x = 1024 return 2048
    assert(bit_manipulation::next_higher_number(1024) == 2048);
    std::cout << "All test cases successfully passed!" << std::endl;
}
/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}


Review comment (suggestion):
```suggestion

    std::cout << "All test cases have successfully passed!" << std::endl;
```


Code after:
}

}  // namespace bit_manipulation

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    // x = 4 return 8
    assert(bit_manipulation::next_higher_number(4) == 8);
    // x = 6 return 9
    assert(bit_manipulation::next_higher_number(6) == 9);
    // x = 13 return 14
    assert(bit_manipulation::next_higher_number(13) == 14);
    // x = 64 return 128
    assert(bit_manipulation::next_higher_number(64) == 128);
    // x = 15 return 23
    assert(bit_manipulation::next_higher_number(15) == 23);
    // x= 32 return 64
    assert(bit_manipulation::next_higher_number(32) == 64);
    // x = 97 return 98
    assert(bit_manipulation::next_higher_number(97) == 98);
    // x = 1024 return 2048
    assert(bit_manipulation::next_higher_number(1024) == 2048);

    std::cout << "All test cases have successfully passed!" << std::endl;
}
/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: bit_manipulation/next_higher_number_with_same_number_of_set_bits.cpp (C++)

Code before:
 * implementation
 *
 * @details
 * Given a number x, find next number with same number of 1 bits in it’s binary representation.
 * For example, consider x = 12, whose binary representation is 1100 (excluding leading zeros on 32 bit machine).
 * It contains two logic 1 bits. The next higher number with two logic 1 bits is 17 (100012).
 *
 * A binary number consists of two digits. They are 0 & 1. Digit 1 is known as
 * set bit in computer terms.
 * @author [Kunal Nayak](https://github.com/Kunal766)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations

/**
 * @namespace bit_manipulation
 * @brief Bit manipulation algorithms
 */
namespace bit_manipulation {
/**
 * @brief The main function implements checking the next number
 * @param x the number that will be calculated
 * @returns a number
 */

uint64_t next_higher_number(uint64_t x)
{
 
  uint64_t rightOne;
  uint64_t nextHigherOneBit;
  uint64_t rightOnesPattern;
 
  uint64_t next = 0;
 
  if(x)
  {
 
    // right most set bit
    rightOne = x & -(signed)x;
 
    // reset the pattern and set next higher bit
    // left part of x will be here
    nextHigherOneBit = x + rightOne;
 
    // nextHigherOneBit is now part [D] of the above explanation.
 
    // isolate the pattern
    rightOnesPattern = x ^ nextHigherOneBit;
 
    // right adjust pattern

Review comment (suggestion):
```suggestion

/**
 * @brief The main function implements checking the next number
 * @param x the number that will be calculated
 * @returns a number
 */
```

Code after:
 * implementation
 *
 * @details
 * Given a number x, find next number with same number of 1 bits in it’s binary representation.
 * For example, consider x = 12, whose binary representation is 1100 (excluding leading zeros on 32 bit machine).
 * It contains two logic 1 bits. The next higher number with two logic 1 bits is 17 (100012).
 *
 * A binary number consists of two digits. They are 0 & 1. Digit 1 is known as
 * set bit in computer terms.
 * @author [Kunal Nayak](https://github.com/Kunal766)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations

/**
 * @namespace bit_manipulation
 * @brief Bit manipulation algorithms
 */
namespace bit_manipulation {

/**
 * @brief The main function implements checking the next number
 * @param x the number that will be calculated
 * @returns a number
 */
uint64_t next_higher_number(uint64_t x)
{
 
  uint64_t rightOne;
  uint64_t nextHigherOneBit;
  uint64_t rightOnesPattern;
 
  uint64_t next = 0;
 
  if(x)
  {
 
    // right most set bit
    rightOne = x & -(signed)x;
 
    // reset the pattern and set next higher bit
    // left part of x will be here
    nextHigherOneBit = x + rightOne;
 
    // nextHigherOneBit is now part [D] of the above explanation.
 
    // isolate the pattern
    rightOnesPattern = x ^ nextHigherOneBit;
 
    // right adjust pattern
Repository: TheAlgorithms/C-Plus-Plus
File: math/factorial.cpp (C++)

Code before:
/**
 * @file
 * @brief Find the [factorial](https://en.wikipedia.org/wiki/Factorial) of a given number
 * @description calculates factorial via recursion
 * \f[n! = n\times(n-1)\times(n-2)\times(n-3)\times\ldots\times3\times2\times1
 *       = n\times(n-1)!\f]
 * for example:
 * \f$5! = 5\times4! = 5\times4\times3\times2\times1 = 120\f$
 *
 * @author [Akshay Gupta](https://github.com/Akshay1910)
 */

#include <cstdint>   /// for uint64_t
#include <iostream>  /// for I/O operations
#include <cassert>   /// for assert

/**
 * @namespace
 * @brief Mathematical algorithms
 */
namespace math {

/**
 * @brief function to find factorial of given number
 * @warning Maximum value for the parameter is 20 as 21!
 * cannot be represented in 64 bit unsigned int
 */
uint64_t factorial(uint8_t n) {
    if (n < 20) {

Review comment (suggestion):
AFAIK, `@description` is invalid. `@details` should be used.
```suggestion
 * @details Calculate factorial via recursion
```


Code after:
/**
 * @file
 * @brief Find the [factorial](https://en.wikipedia.org/wiki/Factorial) of a
 * given number
 * @details Calculate factorial via recursion
 * \f[n! = n\times(n-1)\times(n-2)\times(n-3)\times\ldots\times3\times2\times1
 *       = n\times(n-1)!\f]
 * for example:
 * \f$5! = 5\times4! = 5\times4\times3\times2\times1 = 120\f$
 *
 * @author [Akshay Gupta](https://github.com/Akshay1910)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for I/O operations

/**
 * @namespace
 * @brief Mathematical algorithms
 */
namespace math {

/**
 * @brief function to find factorial of given number
 * @param n is the number which is to be factorialized
 * @warning Maximum value for the parameter is 20 as 21!
 * cannot be represented in 64 bit unsigned int
 */
uint64_t factorial(uint8_t n) {
Repository: TheAlgorithms/C-Plus-Plus
File: math/factorial.cpp (C++)

Code before:
/**
 * @file
 * @brief Find the [factorial](https://en.wikipedia.org/wiki/Factorial) of a given number
 * @description calculates factorial via recursion
 * \f[n! = n\times(n-1)\times(n-2)\times(n-3)\times\ldots\times3\times2\times1
 *       = n\times(n-1)!\f]
 * for example:
 * \f$5! = 5\times4! = 5\times4\times3\times2\times1 = 120\f$
 *
 * @author [Akshay Gupta](https://github.com/Akshay1910)
 */

#include <cstdint>   /// for uint64_t
#include <iostream>  /// for I/O operations
#include <cassert>   /// for assert

/**
 * @namespace
 * @brief Mathematical algorithms
 */
namespace math {

/**
 * @brief function to find factorial of given number
 * @warning Maximum value for the parameter is 20 as 21!
 * cannot be represented in 64 bit unsigned int
 */
uint64_t factorial(uint8_t n) {
    if (n < 20) {
        throw std::invalid_argument("maximum value is 20\n");
    }
    if (n == 0) {
        return 1;
    }
    return n * factorial(n - 1);
}
} // namespace math


Review comment (suggestion):
AFAIK, `uint_*` types are already included without the need of any external libraries.


Code after:
/**
 * @file
 * @brief Find the [factorial](https://en.wikipedia.org/wiki/Factorial) of a
 * given number
 * @details Calculate factorial via recursion
 * \f[n! = n\times(n-1)\times(n-2)\times(n-3)\times\ldots\times3\times2\times1
 *       = n\times(n-1)!\f]
 * for example:
 * \f$5! = 5\times4! = 5\times4\times3\times2\times1 = 120\f$
 *
 * @author [Akshay Gupta](https://github.com/Akshay1910)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for I/O operations

/**
 * @namespace
 * @brief Mathematical algorithms
 */
namespace math {

/**
 * @brief function to find factorial of given number
 * @param n is the number which is to be factorialized
 * @warning Maximum value for the parameter is 20 as 21!
 * cannot be represented in 64 bit unsigned int
 */
uint64_t factorial(uint8_t n) {
    if (n < 20) {
        throw std::invalid_argument("maximum value is 20\n");
    }
    if (n == 0) {
        return 1;
    }
    return n * factorial(n - 1);
}
}  // namespace math
Repository: TheAlgorithms/C-Plus-Plus
File: range_queries/fenwick_tree.cpp (C++)

Code before:
/**
 * @file
 * @brief [Fenwick Tree](https://en.wikipedia.org/wiki/Fenwick_tree) algorithm
 * implementation
 * @details
 * _From Wikipedia, the free encyclopedia._
 *
 * A Fenwick tree or binary indexed tree (BIT) is a clever implementation of a
 * datastructure called bionomal tree. It can update values and solve range
 * queries with operations that is; commulative, associative and has an
 * inverse for this type of element. It can also solve inmutable range queries
 * (min/max), when operations only are associative over this type of element.
 * Some of these restrictions can be removed, by storing redunant information;
 * like in max/min range queries.
 *
 * @author [Mateusz Grzegorzek](https://github.com/mateusz-grzegorzek)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Range Queries
 */
namespace range_queries {
/**
 * @brief The class that initializes the Fenwick Tree.
 */
class fenwick_tree {
    size_t n = 0;            ///< No. of elements present in input array
    std::vector<int> bit{};  ///< Array that represents Binary Indexed Tree.

    /**

Review comment (suggestion):
```suggestion
 * inverse for this type of element. It can also solve immutable range queries
```

I think you meant "immutable" here but I'm not sure if that makes this sentence any better... I'm not sure I understand what an `immutable range queries` is 😂 

Code after:
/**
 * @file
 * @brief [Fenwick Tree](https://en.wikipedia.org/wiki/Fenwick_tree) algorithm
 * implementation
 * @details
 * _From Wikipedia, the free encyclopedia._
 *
 * A Fenwick tree or binary indexed tree (BIT) is a clever implementation of a
 * datastructure called bionomal tree. It can update values and solve range
 * queries with operations that is; commulative, associative and has an
 * inverse for this type of element. It can also solve immutable range queries
 * (min/max), when operations only are associative over this type of element.
 * Some of these restrictions can be removed, by storing redunant information;
 * like in max/min range queries.
 *
 * @author [Mateusz Grzegorzek](https://github.com/mateusz-grzegorzek)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Range Queries
 */
namespace range_queries {
/**
 * @brief The class that initializes the Fenwick Tree.
 */
class fenwick_tree {
    size_t n = 0;            ///< No. of elements present in input array
    std::vector<int> bit{};  ///< Array that represents Binary Indexed Tree.

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

Code before:
 *
 * @author [Rakshaa Viswanathan](https://github.com/rakshaa2000)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for std::cout
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @brief Checks whether the given element (default is `1`) can jump to the last
 * index.
 * @param nums array of numbers containing the maximum jump (in steps) from that
 * index
 * @returns true  if the index can be reached
 * @returns false if the index can NOT be reached
 */
template <typename T>
bool can_jump(const std::vector<T> &nums) {
    size_t lastPos = nums.size() - 1;
    for (int i = nums.size() - 1; i >= 0; i--) {
        if (i + nums[i] >= lastPos) {
            lastPos = i;
        }
    }
    return lastPos == 0;
}
}  // namespace greedy_algorithms

/**
 * @brief Function to test the above algorithm
 * @returns void
 */
static void test() {
    // 1st test
    std::vector<int> nums = { 4, 3, 1, 0, 5 };
    assert(greedy_algorithms::can_jump(nums) == true);

    // 2nd test
    nums = { 3, 2, 1, 0, 4 };
    assert(greedy_algorithms::can_jump(nums) == false);

    // 3rd test
    nums = { 5, 9, 4, 7, 15, 3 };
    assert(greedy_algorithms::can_jump(nums) == true);


Review comment (suggestion):
```suggestion
    for (int i = lastPos; i >= 0; i--) {
```

Code after:
 *
 * @author [Rakshaa Viswanathan](https://github.com/rakshaa2000)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for std::cout
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @brief Checks whether the given element (default is `1`) can jump to the last
 * index.
 * @param nums array of numbers containing the maximum jump (in steps) from that
 * index
 * @returns true  if the index can be reached
 * @returns false if the index can NOT be reached
 */
bool can_jump(const std::vector<int> &nums) {
    size_t lastPos = nums.size() - 1;
    for (size_t i = lastPos; i != static_cast<size_t>(-1); i--) {
        if (i + nums[i] >= lastPos) {
            lastPos = i;
        }
    }
    return lastPos == 0;
}
}  // namespace greedy_algorithms

/**
 * @brief Function to test the above algorithm
 * @returns void
 */
static void test() {
    assert(greedy_algorithms::can_jump(std::vector<int>({4, 3, 1, 0, 5})));
    assert(!greedy_algorithms::can_jump(std::vector<int>({3, 2, 1, 0, 4})));
    assert(greedy_algorithms::can_jump(std::vector<int>({5, 9, 4, 7, 15, 3})));
    assert(!greedy_algorithms::can_jump(std::vector<int>({1, 0, 5, 8, 12})));
    assert(greedy_algorithms::can_jump(std::vector<int>({2, 1, 4, 7})));

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
Repository: TheAlgorithms/C-Plus-Plus
File: greedy_algorithms/jump_game.cpp (C++)

Code before:
 * we reach the lastPos as 0, then the destination can be reached from the start
 * position.
 *
 * @author [Rakshaa Viswanathan](https://github.com/rakshaa2000)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for std::cout
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @brief Checks whether the given element (default is `1`) can jump to the last
 * index.
 * @param nums array of numbers containing the maximum jump (in steps) from that
 * index
 * @returns true  if the index can be reached
 * @returns false if the index can NOT be reached
 */
template <typename T>
bool can_jump(const std::vector<T> &nums) {
    size_t lastPos = nums.size() - 1;
    for (int i = nums.size() - 1; i >= 0; i--) {
        if (i + nums[i] >= lastPos) {
            lastPos = i;
        }
    }
    return lastPos == 0;
}
}  // namespace greedy_algorithms

/**
 * @brief Function to test the above algorithm
 * @returns void
 */
static void test() {
    // 1st test
    std::vector<int> nums = { 4, 3, 1, 0, 5 };
    assert(greedy_algorithms::can_jump(nums) == true);

    // 2nd test
    nums = { 3, 2, 1, 0, 4 };
    assert(greedy_algorithms::can_jump(nums) == false);

    // 3rd test
    nums = { 5, 9, 4, 7, 15, 3 };

Review comment (suggestion):
```suggestion
    const size_t lastPos = nums.size() - 1;
```

Code after:
 * we reach the lastPos as 0, then the destination can be reached from the start
 * position.
 *
 * @author [Rakshaa Viswanathan](https://github.com/rakshaa2000)
 * @author [David Leal](https://github.com/Panquesito7)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for std::cout
#include <vector>    /// for std::vector

/**
 * @namespace
 * @brief Greedy Algorithms
 */
namespace greedy_algorithms {
/**
 * @brief Checks whether the given element (default is `1`) can jump to the last
 * index.
 * @param nums array of numbers containing the maximum jump (in steps) from that
 * index
 * @returns true  if the index can be reached
 * @returns false if the index can NOT be reached
 */
bool can_jump(const std::vector<int> &nums) {
    size_t lastPos = nums.size() - 1;
    for (size_t i = lastPos; i != static_cast<size_t>(-1); i--) {
        if (i + nums[i] >= lastPos) {
            lastPos = i;
        }
    }
    return lastPos == 0;
}
}  // namespace greedy_algorithms

/**
 * @brief Function to test the above algorithm
 * @returns void
 */
static void test() {
    assert(greedy_algorithms::can_jump(std::vector<int>({4, 3, 1, 0, 5})));
    assert(!greedy_algorithms::can_jump(std::vector<int>({3, 2, 1, 0, 4})));
    assert(greedy_algorithms::can_jump(std::vector<int>({5, 9, 4, 7, 15, 3})));
    assert(!greedy_algorithms::can_jump(std::vector<int>({1, 0, 5, 8, 12})));
    assert(greedy_algorithms::can_jump(std::vector<int>({2, 1, 4, 7})));

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/stack_using_array.cpp (C++)

Code before:

    /**
     * @brief Pushes an element onto the stack
     *
     * @param element Element to push onto the stack
     * @return true if the element was successfully pushed onto the stack, false
     * otherwise
     */
    bool push(T element) {
        if (full()) {
            return false;
        } else {
            stack[stackIndex++] = element;
            return true;
        }
    }

    /**
     * @brief Pops an element from the stack
     *
     * @return The popped element
     * @throws std::out_of_range if the stack is empty
     */
    T pop() {
        if (empty()) {
            throw std::out_of_range("Stack is empty");
        } else {
            return stack[--stackIndex];
        }
    }

    /**
     * @brief Displays all elements in the stack
     */
    void show() {
        for (int i = 0; i < stackIndex; i++) {
            std::cout << stack[i] << "\n";
        }
    }

    /**
     * @brief Displays the topmost element of the stack
     *
     * @return The topmost element of the stack
     * @throws std::out_of_range if the stack is empty
     */
    T topmost() const {
        if (empty()) {
            throw std::out_of_range("Stack is empty");
        } else {
            return stack[stackIndex - 1];

Review comment (bug):
```suggestion
            throw std::out_of_range("Stack underflow");
```


Code after:
    /**
     * @brief Pops an element from the stack
     *
     * @return The popped element
     * @throws std::out_of_range if the stack is empty
     */
    T pop() {
        if (empty()) {
            throw std::out_of_range("Stack underflow");
        }
        return stack[stackIndex--];
    }

    /**
     * @brief Displays all elements in the stack
     */
    void show() const {
        for (int i = 0; i <= stackIndex; i++) {
            std::cout << stack[i] << "\n";
        }
    }

    /**
     * @brief Displays the topmost element of the stack
     *
     * @return The topmost element of the stack
     * @throws std::out_of_range if the stack is empty
     */
    T topmost() const {
        if (empty()) {
            throw std::out_of_range("Stack underflow");
        }
        return stack[stackIndex];
    }

    /**
     * @brief Displays the bottom element of the stack
     *
     * @return The bottom element of the stack
     * @throws std::out_of_range if the stack is empty
     */
    T bottom() const {
        if (empty()) {
            throw std::out_of_range("Stack underflow");
        }
        return stack[0];
    }
};
}  // namespace data_structures

/**
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/stack_using_array.cpp (C++)

Code before:
     *
     * @return true if the stack is full, false otherwise
     */
    bool full() const { return stackIndex == stackSize; }

    /**
     * @brief Checks if the stack is empty
     *
     * @return true if the stack is empty, false otherwise
     */
    bool empty() const { return stackIndex == 0; }

    /**
     * @brief Pushes an element onto the stack
     *
     * @param element Element to push onto the stack
     * @return true if the element was successfully pushed onto the stack, false
     * otherwise
     */
    bool push(T element) {
        if (full()) {
            return false;
        } else {
            stack[stackIndex++] = element;
            return true;
        }
    }

    /**
     * @brief Pops an element from the stack
     *
     * @return The popped element
     * @throws std::out_of_range if the stack is empty
     */
    T pop() {
        if (empty()) {
            throw std::out_of_range("Stack is empty");
        } else {
            return stack[--stackIndex];
        }
    }

    /**
     * @brief Displays all elements in the stack
     */
    void show() {
        for (int i = 0; i < stackIndex; i++) {
            std::cout << stack[i] << "\n";
        }
    }


Review comment (bug):
```suggestion
    void push(T element) {
        if (full()) {
            throw std::out_of_range("Stack overflow");
        } else {
            stack[stackIndex++] = element;
        }
```


Code after:
     *
     * @param element Element to push onto the stack
     */
    void push(T element) {
        if (full()) {
            throw std::out_of_range("Stack overflow");
        } else {
            stack[++stackIndex] = element;
        }
    }

    /**
     * @brief Pops an element from the stack
     *
     * @return The popped element
     * @throws std::out_of_range if the stack is empty
     */
    T pop() {
        if (empty()) {
            throw std::out_of_range("Stack underflow");
        }
        return stack[stackIndex--];
    }

    /**
     * @brief Displays all elements in the stack
     */
    void show() const {
        for (int i = 0; i <= stackIndex; i++) {
            std::cout << stack[i] << "\n";
        }
    }

    /**
     * @brief Displays the topmost element of the stack
     *
     * @return The topmost element of the stack
     * @throws std::out_of_range if the stack is empty
     */
    T topmost() const {
        if (empty()) {
            throw std::out_of_range("Stack underflow");
        }
        return stack[stackIndex];
    }

    /**
     * @brief Displays the bottom element of the stack
     *
     * @return The bottom element of the stack
     * @throws std::out_of_range if the stack is empty