Language: C++

#include <iostream>
#include <vector>

using namespace std;

namespace util {
    template<typename T >
    vector<T> read_vector(function<T(string)> parse_func) {
        int n;
        cin >> n;

        vector<T> v;
        for (int i = 0; i < n; i++) {
            string in;
            cin >> in;
            v.push_back(parse_func(in));
        }
        return v;
    }

    template<typename T >
    void print_vector(vector<T> &v) {
        for (auto it = v.begin(); it != v.end(); it++) {
            cout << *it;
            if (it + 1 != v.end())
                cout << " ";
        }
        cout << endl;
    }

    template<typename T >
    void swap(vector<T>& v, size_t i, size_t j) {
        T tmp = v[i];
        v[i] = v[j];
        v[j] = tmp;
    }

    template<typename T >
    bool is_stable(vector<T>& src, vector<T>& sorted,
                   function<bool(const T&, const T&)> same_value, function<bool(const T&, const T&)> identical) {
        for (auto it = sorted.begin(); it != sorted.end()-1; it++) {
            T current = *it;
            T next = *(it+1);

            if (same_value(current,next)) {
                size_t current_idx = 0;
                for (size_t i = 0; i < src.size(); i++){
                    if (identical(src[i], current)) {
                        current_idx = i;
                        break;
                    }
                }

                size_t next_idx = 0;
                for (size_t i = 0; i < src.size(); i++){
                    if (identical(src[i], next)) {
                        next_idx = i;
                        break;
                    }
                }
                if (current_idx > next_idx)
                    return false;
            }
        }
        return true;
    }

    void print_stable(bool is_stable) {
       if (is_stable) {
           cout << "Stable";
       } else {
           cout << "Not Stable";
       }
        cout << endl;
    }
}

namespace {
    class Card {
    private:
        char suit;
        int value;
    public:
        Card(char _suit, int _value) : suit(_suit), value(_value) {}

        bool same_suit(const Card& c) const { return suit == c.suit; }
        bool same_value(const Card& c) const { return value == c.value; }

        friend ostream& operator<<(ostream& os, const Card& c);
        friend bool operator< (const Card& lhs, const Card& rhs);
        friend bool operator> (const Card& lhs, const Card& rhs);
        friend bool operator<= (const Card& lhs, const Card& rhs);
        friend bool operator>= (const Card& lhs, const Card& rhs);
    };
    ostream& operator<<(ostream& os, const Card& c) {
        os << c.suit << c.value;
        return os;
    }
    inline bool operator< (const Card& lhs, const Card& rhs) { return lhs.value < rhs.value; }
    inline bool operator> (const Card& lhs, const Card& rhs) { return rhs < lhs; }
    inline bool operator<= (const Card& lhs, const Card& rhs) { return !(lhs > rhs); }
    inline bool operator>= (const Card& lhs, const Card& rhs) { return !(lhs < rhs); }

    template<typename T>
    int run_bubble_sort(vector<T>& v) {
        int count = 0;
        for (size_t i = 0; i < v.size(); i++) {
            for (size_t j = v.size() - 1; j > i; j--) {
                if (v[j] < v[j-1]) {
                    count++;
                    util::swap(v,j,j-1);
                }
            }
        }
        return count;
    }

    template<typename T>
    int run_selection_sort(vector<T>& v) {
        int count = 0;
        for (size_t i = 0; i < v.size(); i++) {
            size_t min = i;
            for (size_t j = i; j < v.size(); j++) {
                if (v[j] < v[min])
                    min = j;
            }

            if (min != i) {
                count++;
                util::swap(v,i,min);
            }
        }
        return count;
    }
}

int main() {
    vector<Card> in = util::read_vector<Card>([](string s){
        return Card(s[0], stoi(s.substr(1)));
    });

    vector<Card> bubble(in);
    vector<Card> selection(in);

    run_bubble_sort(bubble);
    run_selection_sort(selection);

    auto same_value = [](const Card& lhs, const Card& rhs) -> bool { return lhs.same_value(rhs); };
    auto identical = [](const Card& lhs, const Card& rhs) -> bool { return lhs.same_value(rhs) && lhs.same_suit(rhs); };

    util::print_vector(bubble);
    util::print_stable(util::is_stable<Card>(in, bubble, same_value, identical));
    util::print_vector(selection);
    util::print_stable(util::is_stable<Card>(in, selection, same_value, identical));

    return 0;
}

Compiler output:
a.cc:8:27: error: 'function' was not declared in this scope
    8 |     vector<T> read_vector(function<T(string)> parse_func) {
      |                           ^~~~~~~~
a.cc:3:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    2 | #include <vector>
  +++ |+#include <functional>
    3 | 
a.cc:8:37: error: expected primary-expression before '(' token
    8 |     vector<T> read_vector(function<T(string)> parse_func) {
      |                                     ^
a.cc:8:44: error: expected primary-expression before ')' token
    8 |     vector<T> read_vector(function<T(string)> parse_func) {
      |                                            ^
a.cc:8:47: error: 'parse_func' was not declared in this scope
    8 |     vector<T> read_vector(function<T(string)> parse_func) {
      |                                               ^~~~~~~~~~
a.cc:8:58: error: expected ';' before '{' token
    8 |     vector<T> read_vector(function<T(string)> parse_func) {
      |                                                          ^~
      |                                                          ;
a.cc:40:20: error: 'function' has not been declared
   40 |                    function<bool(const T&, const T&)> same_value, function<bool(const T&, const T&)> identical) {
      |                    ^~~~~~~~
a.cc:40:28: error: expected ',' or '...' before '<' token
   40 |                    function<bool(const T&, const T&)> same_value, function<bool(const T&, const T&)> identical) {
      |                            ^
a.cc: In function 'int main()':
a.cc:138:46: error: no match for call to '(std::vector<{anonymous}::Card>) (main()::<lambda(std::string)>)'
  138 |     vector<Card> in = util::read_vector<Card>([](string s){
      |                       ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
  139 |         return Card(s[0], stoi(s.substr(1)));
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  140 |     });
      |     ~~                                        
a.cc:152:45: error: no matching function for call to 'is_stable<{anonymous}::Card>(std::vector<{anonymous}::Card>&, std::vector<{anonymous}::Card>&, main()::<lambda(const {anonymous}::Card&, const {anonymous}::Card&)>&, main()::<lambda(const {anonymous}::Card&, const {anonymous}::Card&)>&)'
  152 |     util::print_stable(util::is_stable<Card>(in, bubble, same_value, identical));
      |                        ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:10: note: candidate: 'template<class T> bool util::is_stable(std::vector<T>&, std::vector<T>&, int)'
   39 |     bool is_stable(vector<T>& src, vector<T>& sorted,
      |          ^~~~~~~~~
a.cc:39:10: note:   candidate expects 3 arguments, 4 provided
a.cc:154:45: error: no matching function for call to 'is_stable<{anonymous}::Card>(std::vector<{anonymous}::Card>&, std::vector<{anonymous}::Card>&, main()::<lambda(const {anonymous}::Card&, const {anonymous}::Card&)>&, main()::<lambda(const {anonymous}::Card&, const {anonymous}::Card&)>&)'
  154 |     util::print_stable(util::is_stable<Card>(in, selection, same_value, identical));
      |                        ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:10: note: candidate: 'template<class T> bool util::is_stable(std::vector<T>&, std::vector<T>&, int)'
   39 |     bool is_stable(vector<T>& src, vector<T>& sorted,
      |          ^~~~~~~~~
a.cc:39:10: note:   candidate expects 3 arguments, 4 provided