c++ - Sort array/vector of string -


how can sort array/vector repetition of elements? example

input

leo mike eric leo leo 

output _ _ _ or

leo       leo leo       eric leo       mike eric mike 

i recommend processing data in 3 passes:

  1. use std::sort repeated elements adjacent each other.

  2. iterate on sorted range recording length , position of each equal_range.

  3. now can resort sequence based on data you've recovered in step 2. may consider using stable_search in phase if secondary search key alphabetical.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -