Selection_sort C++11

0

Szukam pomocy przy programie z funkcją selection sort...
Program sam w sobie działa tak jak powinien jednak chciałbym by funkcja selection sort była zmuszona do wyświetlania kolejnych kroków sortowania w konsoli.
Nie wiem jak rozwiązać ten problem, będę wdzięczny za każdą dostępną pomoc!

#include <iostream>
#include <vector>
 
 
template <typename T>
void write_vector(std::vector<T> const & V)
{
  for(int i=0; i < V.size(); i++)
 
    std::cout << V[i] << " " ;
    std::cout << std::endl;
 
}
 
template <typename T>
 void selection (std::vector<T> & V) {
        int const len = V.size();
        // For each V(i)...
        for (int i = 0; i < len; i++) {
            int min = i;
 
            // Find the minimum of V(i+1..n).
            for (int j = i + 1; j < len; j++) {
                T & t1 = V.at(min);
                T & t2 = V.at(j);
 
                if (V.at(min) > V.at(j))
                    min = j;
            }
 
            // Swap V(i) with the minimum.
            if (i != min)
                std::swap(V.at(i), V.at(min));
 
{
                std::cout << V[i] << " ";
}
 
        }
        std::cout << std::endl;
   }
 
 
int main()
{
  int input;
  std::vector<int> V;
  while (std::cin >> input)
  {
    V.push_back(input);
  }
  write_vector(V);
  selection(V);
  return 0;
}
1

A tak najprościej?

#include <iostream>
#include <vector>

template <typename T>
void write_vector(std::vector<T> const & V)
{
  for(int i=0; i < V.size(); i++)

    std::cout << V[i] << " " ;
    std::cout << std::endl;

}

template <typename T>
 void selection (std::vector<T> & V) {
        int const len = V.size();
        // For each V(i)...
        for (int i = 0; i < len; i++) {
            int min = i;

            // Find the minimum of V(i+1..n).
            for (int j = i + 1; j < len; j++) {
                T & t1 = V.at(min);
                T & t2 = V.at(j);

                if (V.at(min) > V.at(j))
                    min = j;
            }

            // Swap V(i) with the minimum.
            if (i != min)
                std::swap(V.at(i), V.at(min));

{				std::cout <<"printing sorting"<<"\n";
                write_vector(V);
}

        }
        std::cout << std::endl;
   }

int main()
{
  int input;
  std::vector<int> V;
  while (std::cin >> input)
  {
    V.push_back(input);
  }
  write_vector(V);
  selection(V);
  return 0;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1