**EDIT** **Took a different approach and found the solution, updated the function to correctly find the mode or modes**

I've been at this algorithm all day and night, I've looked at about 12 code examples 10x over but none of them seem to go above and beyond to address my problem.

**Problem:** Find the mode(s) in an array, if the array has more than one mode, display them all. (This is a homework assignment so I must use arrays/pointers)

Sample array:
-1, -1, 5, 6, 1, 1

Sample output:
This array has the following mode(s): -1, 1

The problem I'm having is trying to figure how to store and display just the highest mode OR the multiple modes if they exist.

I have used a lot of approaches and so I will post my most recent approach:

```
void getMode(int *arr, int size)
{
    int *count = new int[size]; // to hold the number of times a value appears in the array

    // fill the count array with zeros
    for (int i = 0; i < size; i++)
        count[i] = 0;

    // find the possible modes
    for (int x = 0; x < size; x++)
    {
        for (int y = 0; y < size; y++)
        {
            // don't count the values that will always occur at the same element
            if (x == y)
                continue;

            if (arr[x] == arr[y])
                count[x]++;
        }
    }

    // find the the greatest count occurrences
    int maxCount = getMaximum(count, size);

    // store only unique values in the mode array
    int *mode = new int[size]; // to store the mode(s) in the list
    int modeCount = 0; // to count the number of modes
    if (maxCount > 0)
    {
        for (int i = 0; i < size; i++)
        {
            if (count[i] == maxCount)
            {
                // call to function searchList
                if (!searchList(mode, modeCount, arr[i]))
                {
                    mode[modeCount] = arr[i];
                    modeCount++;
                }
            }
        }
    }

    // display the modes
    if (modeCount == 0)
        cout << "The list has no mode\n";
    else if (modeCount == 1)
    {
        cout << "The list has the following mode: " << mode[0] << endl;
    }
    else if (modeCount > 1)
    {
        cout << "The list has the following modes: ";

        for (int i = 0; i < modeCount - 1; i++)
        {
            cout << mode[i] << ", ";
        }
        cout << mode[modeCount - 1] << endl;
    }

    // delete the dynamically allocated arrays
    delete[]count;
    delete[]mode;
    count = NULL;
    mode = NULL;
}

/*
    definition of function searchList.
    searchList accepts a pointer to an int array, its size, and a value to be searched for as its arguments.
    if searchList finds the value to be searched for, searchList returns true.
*/

bool searchList(int *arr, int size, int value)
{
    for (int x = 0; x < size; x++)
    {
        if (arr[x] == value)
        {
            return true;
        }
    }
    return false;
}

```