Language: C++

#include <array>

class MySorter
{
private:
    ISorter *sorter;
public:
    MySorter(ISorter *sorter);
    ~MySorter();
    bool Sort(std::vector<int> array);
};

#include <vector>
class InsertionSort : public ISorter
{
public:
    bool Sort(std::vector<int>&);
    InsertionSort();
    ~InsertionSort();
};

#include <vector>
class InsertionSort : public ISorter
{
public:
    bool Sort(std::vector<int>&);
    InsertionSort();
    ~InsertionSort();
};

// InsertionSort.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <memory>

void printArray(const std::vector<int> &array);
std::vector<int> readArray(void);

int main()
{
    int n = 0;
    std::string input;
    std::getline(std::cin, input);
    n = std::stoi(input);

    std::vector<int> array = readArray();

    std::unique_ptr<InsertionSort> algorithm = std::make_unique<InsertionSort>();
    std::unique_ptr<MySorter> sorter = std::make_unique<MySorter>(algorithm.get());

    sorter->Sort(array);

    return 0;
}


void printArray(const std::vector<int> &array)
{
    for (unsigned int k = 0; k < array.size(); k++) {
        std::cout << array[k];
        if (k != array.size() - 1) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

std::vector<int> readArray(void)
{
    std::string input;
    std::vector<int> array;

    std::getline(std::cin, input);
    std::stringstream ss(input);

    std::string buf;
    while (ss >> buf) {
        array.push_back(std::stoi(buf));
    }

    return array;
}


#include <memory>

MySorter::MySorter(ISorter *sorter)
{
    this->sorter = sorter;
}

MySorter::~MySorter()
{
}

bool MySorter::Sort(std::vector<int> array)
{
    return sorter->Sort(array);
}

#include <iostream>

InsertionSort::InsertionSort()
{
}

InsertionSort::~InsertionSort()
{
}

bool InsertionSort::Sort(std::vector<int> &array)
{
    int n = array.size();

    for (int i = 0, j = 0; i < n; i++) {
        auto v = array[i];
        j = i - 1;
        while (j >= 0 && array[j] > v) {
            array[j + 1] = array[j];
            j--;
        }
        array[j + 1] = v;

        for (unsigned int k = 0; k < array.size(); k++) {
            std::cout << array[k];
            if (k != array.size() - 1) {
                std::cout << " ";
            }
        }
        std::cout << std::endl;
    }

    return true;
}


Compiler output:
a.cc:6:5: error: 'ISorter' does not name a type; did you mean 'MySorter'?
    6 |     ISorter *sorter;
      |     ^~~~~~~
      |     MySorter
a.cc:8:21: error: expected ')' before '*' token
    8 |     MySorter(ISorter *sorter);
      |             ~       ^~
      |                     )
a.cc:10:15: error: 'std::vector' has not been declared
   10 |     bool Sort(std::vector<int> array);
      |               ^~~
a.cc:10:26: error: expected ',' or '...' before '<' token
   10 |     bool Sort(std::vector<int> array);
      |                          ^
a.cc:15:1: error: expected class-name before '{' token
   15 | {
      | ^
a.cc:23:7: error: redefinition of 'class InsertionSort'
   23 | class InsertionSort : public ISorter
      |       ^~~~~~~~~~~~~
a.cc:14:7: note: previous definition of 'class InsertionSort'
   14 | class InsertionSort : public ISorter
      |       ^~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:55:18: error: cannot convert 'std::vector<int>' to 'int'
   55 |     sorter->Sort(array);
      |                  ^~~~~
      |                  |
      |                  std::vector<int>
a.cc:10:15: note:   initializing argument 1 of 'bool MySorter::Sort(int)'
   10 |     bool Sort(std::vector<int> array);
      |               ^~~~~~~~~~~
a.cc: At global scope:
a.cc:91:19: error: expected constructor, destructor, or type conversion before '(' token
   91 | MySorter::MySorter(ISorter *sorter)
      |                   ^
a.cc:100:6: error: no declaration matches 'bool MySorter::Sort(std::vector<int>)'
  100 | bool MySorter::Sort(std::vector<int> array)
      |      ^~~~~~~~
a.cc:10:10: note: candidate is: 'bool MySorter::Sort(int)'
   10 |     bool Sort(std::vector<int> array);
      |          ^~~~
a.cc:3:7: note: 'class MySorter' defined here
    3 | class MySorter
      |       ^~~~~~~~
In file included from /usr/include/c++/14/memory:78,
                 from a.cc:38:
/usr/include/c++/14/bits/unique_ptr.h: In instantiation of 'std::__detail::__unique_ptr_t<_Tp> std::make_unique(_Args&& ...) [with _Tp = MySorter; _Args = {InsertionSort*}; __detail::__unique_ptr_t<_Tp> = __detail::__unique_ptr_t<MySorter>]':
a.cc:53:66:   required from here
   53 |     std::unique_ptr<MySorter> sorter = std::make_unique<MySorter>(algorithm.get());
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/unique_ptr.h:1077:30: error: no matching function for call to 'MySorter::MySorter(InsertionSort*)'
 1077 |     { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:3:7: note: candidate: 'constexpr MySorter::MySorter()'
    3 | class MySorter
      |       ^~~~~~~~
a.cc:3:7: note:   candidate expects 0 arguments, 1 provided
a.cc:3:7: note: candidate: 'constexpr MySorter::MySorter(const MySorter&)'
a.cc:3:7: note:   no known conversion for argument 1 from 'InsertionSort*' to 'const MySorter&'