Мне нужно взять вектор C++ с потенциально большим количеством элементов, удалить дубликаты и отсортировать его.
Сейчас у меня есть приведенный ниже код, но его нет. не работает.
Код: Выделить всё
vec.erase(
std::unique(vec.begin(), vec.end()),
vec.end());
std::sort(vec.begin(), vec.end());
Additionally, is it faster to erase the duplicates first (similar to coded above) or perform the sort first? If I do perform the sort first, is it guaranteed to remain sorted after std::unique is executed?
Or is there another (perhaps more efficient) way to do all this?
Источник: https://stackoverflow.com/questions/104 ... t-a-vector
Мобильная версия