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

Code before:
 * We can perform basic CRUD operations as well as other operations like sorting etc.
 *
 * ### Algorithm
 * It implements various method like insert, sort, search etc. efficiently.
 * You can select the operation and methods will do the rest work for you.
 * You can insert element, sort them in order, search efficiently, delete values and print the list.
 */

#include <iostream> /// for io operations
#include <array>   /// for std::array
#include <cassert> /// for assert

/**
 * @namespace data_structures
 * @brief Algorithms with data structures
 */
namespace data_structures {
/**
 * @namespace list_array
 * @brief Functions for [Dynamic Array](https://en.wikipedia.org/wiki/Dynamic_array) algorithm
 */
namespace list_array {
    /**
     * @brief Structure of List with supporting methods.
     */
    template <int N>
    struct list {
        std::array<uint64_t, N> data{}; // Array that implement list
        uint64_t top = 0; // Pointer to the last element
        bool isSorted = false; // indicator whether list is sorted or not
        /**
         * @brief Search an element in the list using binarySearch.
         * @param dataArr list
         * @param first pointer to the first element in the remaining list
         * @param last pointer to the last element in the remaining list
         * @param val element that will be searched
         * @return index of element in the list if present else -1
         */
        uint64_t BinarySearch(const std::array<uint64_t, N> &dataArr, const uint64_t &first, const uint64_t &last,
                              const uint64_t &val) {
            // If both pointer cross each other means no element present in the list which is equal to the val
            if (last < first) {
                return -1;
            }
            uint64_t mid = (first + last) / 2;
            // check whether current mid pointer value is equal to element or not
            if (dataArr[mid] == val)
                return mid;
                // if current mid value is greater than  element we have to search in first half
            else if (val < dataArr[mid])
                return (BinarySearch(dataArr, first, mid - 1, val));

Review comment (suggestion):
I believe we should use `uint64_t` in here like the other values.
```suggestion
    template <uint64_t N>
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix&nbsp; | &nbsp;**Tags:** Not maintainable


Code after:
 * We can perform basic CRUD operations as well as other operations like sorting etc.
 *
 * ### Algorithm
 * It implements various method like insert, sort, search etc. efficiently.
 * You can select the operation and methods will do the rest work for you.
 * You can insert element, sort them in order, search efficiently, delete values and print the list.
 */

#include <iostream> /// for io operations
#include <array>   /// for std::array
#include <cassert> /// for assert

/**
 * @namespace data_structures
 * @brief Algorithms with data structures
 */
namespace data_structures {
/**
 * @namespace list_array
 * @brief Functions for [Dynamic Array](https://en.wikipedia.org/wiki/Dynamic_array) algorithm
 */
namespace list_array {
    /**
     * @brief Structure of List with supporting methods.
     */
    template <uint64_t N>
    struct list {
        std::array<uint64_t, N> data{}; // Array that implement list
        uint64_t top = 0; // Pointer to the last element
        bool isSorted = false; // indicator whether list is sorted or not
        /**
         * @brief Search an element in the list using binarySearch.
         * @param dataArr list
         * @param first pointer to the first element in the remaining list
         * @param last pointer to the last element in the remaining list
         * @param val element that will be searched
         * @return index of element in the list if present else -1
         */
        uint64_t BinarySearch(const std::array<uint64_t, N> &dataArr, const uint64_t &first, const uint64_t &last,
                              const uint64_t &val) {
            // If both pointer cross each other means no element present in the list which is equal to the val
            if (last < first) {
                return -1;
            }
            uint64_t mid = (first + last) / 2;
            // check whether current mid pointer value is equal to element or not
            if (dataArr[mid] == val)
                return mid;
                // if current mid value is greater than  element we have to search in first half
            else if (val < dataArr[mid])
                return (BinarySearch(dataArr, first, mid - 1, val));