C++ Programming Question:

profileadelen
 (Not rated)
 (Not rated)
Chat

  

C++ Programming Question:

1. Replace the array with an STL container that supports operator []
2. Use STL algorithms replacing existing logic where possible
3. Use lambda expressions or functors to support sorting

void algorithm(int* arr, int n)
{
           int count = 0;
           for (int i = 0; i < n; i++)
                 if (arr[i] == 0)
                         count++;
            for (int i = 0; i < count; i++)
                 arr[i] = 0;
            for (int i = count; i < n; i++)
                 arr[i] = 1;
            // provide support for using std::sort
   sort( arr[0], arr[n-1], { functor or lambda } );
}

    • 7 years ago
    answer
    NOT RATED

    Purchase the answer to view it

    blurred-text