#include <iostream>
#include <algorithm>
#include <vector>

void print(std::vector<int> stapel)
{
	std::cout << "[ ";
	for (auto e : stapel) std::cout << e << ' ';
	std::cout << "]\n";
}

auto finde_maximum(std::vector<int> stapel, size_t start)
{
	auto m = start;
	for (auto n = m; n < stapel.size(); ++n)
	{
		if (stapel[n] > stapel[m])
		{
			m = n;
		}
	}
	return m;
}

std::vector<int> umdrehen(std::vector<int> stapel, size_t index)
{
	std::reverse(stapel.begin() + index, stapel.end());
	std::cout << "[ ";
	for (size_t i = 0; i < stapel.size(); ++i)
	{
		if (i == index) std::cout << "][ ";
		std::cout << stapel[i] << ' ';
	}
	std::cout << "]\n";
	return stapel;
}

std::vector<int> wendungen(std::vector<int> stapel)
{
	print(stapel);
	auto wendungen = std::vector<int>{};
	for (size_t n = 0; n < stapel.size(); ++n)
	{
		auto m = finde_maximum(stapel, n);
		if (m > n)
		{
			stapel = umdrehen(stapel, m);
			stapel = umdrehen(stapel, n);
			wendungen.push_back(m);
			wendungen.push_back(n);
		}
	}
	print(stapel);
	return wendungen;
}

int main()
{
	auto stapel = std::vector{ 4,1,3,2 };
	auto w = wendungen(stapel);
	std::cout << "Wendepositionen: ";
	print(w);

	stapel = std::vector{ 4,2,3,1 };
	w = wendungen(stapel);
	std::cout << "Wendepositionen: ";
	print(w);
}