#Implementation
Implementation
size - sorted_elements
might not return what you expect ifsize == 0
(it returnsstd::numeric_limits<unsigned int>::max()
). This makes the intended check fail forsize == 0
. This can be fixed by changing the while loops condition tosorted_elements < size && !sorted
.- You could use
std::swap(arr[index], arr[index + 1]);
to swap the elements. This way, the preferred assignment operation (copy or move) forElement
will be used (ifElement
provides its own specialization). Currently, you always copy, which might not always be preferred (e.g. with largestd::string
s).