Language: C++

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
#define A

struct card
{
	card(const card&a) {
		mark = a.mark;
		num = a.num;
	}
	card(const char* str)
	{
		*this = str;
	}
	card() {}

	char mark;
	int	num;

	void operator = (const char * str) {
		mark = str[0];
		num = str[1] - 0x30;
	}
	bool operator < ( const card & right)const {
		return num < right.num;
	}


};

template<typename T>
int bubbleSort(list<T>&arr, int n) {
	int cunt = 0;
	bool cont = true;
	while (cont)
	{
		template<typename T>
		list<T>::iterator it1 = arr.begin(), it2 = arr.begin();
		advance(it2, 1);
		cont = false;
		for (int i = 1; i < n; ++i, advance(it1, 1), advance(it2, 1))
		{
			if ( *it2 < *it1 ) {
				swap(*it1, *it2);
				cont = true;
				cunt++;
			}
		}
	}
	return cunt;
}
template int bubbleSort(list<int>&arr, int n);

template <typename T>
int selectionSort(list<T>& arr, int n) {
	int cunt = 0;
	list<T>::iterator it1, it2, min, itend = arr.end();
	for (it1 = arr.begin(); it1 != itend; advance(it1, 1))
	{
		min = it1;
		for (it2 = next(it1); it2 != itend; advance(it2, 1))
		{
			if (*it2 < *min)
				min = it2;
		}
		if (it1 != min) {
			cunt++;
			swap(*it1, *min);
		}
	}
	return cunt;
}

void listPrint(list<int>& arr) {
	list<int>::iterator it = arr.begin(),itend = arr.end();
	cout << *it;
	advance(it, 1);
	for (; it != itend; advance(it, 1))
		cout << " " << *it;
	cout << endl;
}

#ifdef D
int main(void)
{
	int n;
	cin >> n;
	list<card> arr1, arr2;
	char str[3];
	for (int i = 0 ; i< n; ++i)
	{
		cin >> str;
		card c(str);
		arr1.push_back(c);
		arr2.push_back(c);
	}

	return 0;
}
#endif // D

#ifdef B
int main(void)
{
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto &a : arr)
		cin >> a;
	int cunt = selectionSort(arr,n);
	listPrint(arr);
	cout <<  cunt << endl;
	return 0;
}
#endif // B

#ifdef A
int main(void)
{
	int cunt = 0;
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto& a : arr)
		cin >> a;
	cunt = bubbleSort(arr, n);
	listPrint(arr);
	cout << cunt << endl;
	return 0;
}
#endif // A

Compiler output:
a.cc: In function 'int bubbleSort(std::__cxx11::list<T>&, int)':
a.cc:39:17: error: a template declaration cannot appear at block scope
   39 |                 template<typename T>
      |                 ^~~~~~~~
a.cc:43:53: error: 'it1' was not declared in this scope
   43 |                 for (int i = 1; i < n; ++i, advance(it1, 1), advance(it2, 1))
      |                                                     ^~~
a.cc:43:70: error: 'it2' was not declared in this scope
   43 |                 for (int i = 1; i < n; ++i, advance(it1, 1), advance(it2, 1))
      |                                                                      ^~~
a.cc: In function 'int selectionSort(std::__cxx11::list<T>&, int)':
a.cc:59:9: error: need 'typename' before 'std::__cxx11::list<T>::iterator' because 'std::__cxx11::list<T>' is a dependent scope
   59 |         list<T>::iterator it1, it2, min, itend = arr.end();
      |         ^~~~~~~
a.cc:59:26: error: expected ';' before 'it1'
   59 |         list<T>::iterator it1, it2, min, itend = arr.end();
      |                          ^~~~
      |                          ;
a.cc:60:14: error: 'it1' was not declared in this scope
   60 |         for (it1 = arr.begin(); it1 != itend; advance(it1, 1))
      |              ^~~
a.cc:60:40: error: 'itend' was not declared in this scope
   60 |         for (it1 = arr.begin(); it1 != itend; advance(it1, 1))
      |                                        ^~~~~
a.cc:63:22: error: 'it2' was not declared in this scope
   63 |                 for (it2 = next(it1); it2 != itend; advance(it2, 1))
      |                      ^~~
a.cc:65:37: error: overloaded function with no contextual type information
   65 |                         if (*it2 < *min)
      |                                     ^~~
a.cc:70:37: error: overloaded function with no contextual type information
   70 |                         swap(*it1, *min);
      |                                     ^~~