// Bubble-sort the entry to the right position void NeighborhoodBuilder::insert_(T v, std::vector<T>::iterator it) const { // Is the new value better than one current value if(v.value() <= it->value()) { return; } *it = v; auto prev = it; ++it; for(int i = 1; i < k_; ++i) { // Is this the right place? if(prev->value() < it->value()) { break; } //Nope, the new value has to be advanced to the next field std::swap(*prev, *it); ++it; ++prev; } }