Simple Bubble Sort swap counter C++
Your answer should also be a template struct. It contains first and last element of type big_int but in the bubble _sort function it is constructed with template argument type T.

template&lt;class T&gt;
struct answer {
    std::size_t count;
    T first_element;
    T last_element;
};


But actually maybe the structure Is redundant because first And last element can Always easily be accessed inside the sorted container. Or it could at least contain just references to those elements instead of their copies in case the template argument T is something more complex then long long.

auto count = bubble_sort(v);
auto &amp; first = v[0];
auto &amp; last = v[v.size - 1];


Further instead of accepting vector&lt;T&gt;, you could accept two iterators of template argument type as Is common with many standard functions and allows to work not only for any type of container but also for just a range within a container.

template&lt;class Iterator&gt;
std::size_t bubble_sort(Iterator from, Iterator to);

// ...

auto count = bubble_sort(v.begin(), v.end());