#include <iostream>

class Histogram
{
private:
    int** matrix;
    int lines;
    void SortMatrix();
public:
    Histogram(){ }
    Histogram(int elements[], int elementsNr);
    Histogram(int** m, int l);
    void Print();
};

using namespace std;
Histogram::Histogram(int** m, int l)
{
    matrix=m;
    lines=l;
    SortMatrix();
}

Histogram::Histogram(int elements[], int elementsNr)
{
    lines=0;
    //initialize matrix : elementrNr lines and 2 columns
    matrix=new int*[elementsNr];
    for(int i=0;i<elementsNr;i++)
    {
        matrix[i]=new int[2];
        matrix[i][0]=5;
        matrix[i][1]=5;
    }
    //search each element from the array in the matrix
    bool found=false;
    for(int i=0;i<elementsNr;i++)
    {
        found=false;
        for(int j=0;j<elementsNr;j++)
        {
            //the element was found in the matrix ( on the first column )
            if(matrix[j][0] == elements[i])
            {
                matrix[j][1]++;
                found=true;
                break;
            }
        }
        if(!found)
        {
            matrix[lines][0]=elements[i];
            matrix[lines][1]=1;
            lines++;
        }
    }
    SortMatrix();

}
void Histogram::SortMatrix()
{
    bool flag=true;
    int temp1;
    int temp2;
    int i=0;
    for (int i = 0; (i < lines - 1); i++) {

    for (int o = 0; (o < lines - 1); o++) {

        if ( matrix[ i ][0] < matrix[ o ][0] ) {

            temp1 = matrix[ i ][0];
            temp2 = matrix[ i ][1];

            matrix[ i ][0] = matrix[ o ][0];
            matrix[ i ][1] = matrix[ o ][1];

            matrix[ o ][0] = temp1;
            matrix[ o ][1] = temp2;

        }

    }

}
}
void Histogram::Print()
{

    for(int i=0;i<lines;i++)
    {
        cout<<matrix[i][0]<<" : " <<matrix[i][1]<<endl;
    }

}

int main() {
    int arr[] = {4, 2, 7, 8, 3, 5, 7, 8, 3, 1, 5, 7, 9, 4, 2, 33, 7};
    Histogram h(arr, 17);
    h.Print();
}