sort array of integers lexicographically C++
问题 I want to sort a large array of integers (say 1 millon elements) lexicographically. Example: input [] = { 100, 21 , 22 , 99 , 1 , 927 } sorted[] = { 1 , 100, 21 , 22 , 927, 99 } I have done it using the simplest possible method: convert all numbers to strings (very costly because it will take huge memory) use std:sort with strcmp as comparison function convert back the strings to integers Is there a better method than this? 回答1: Use std::sort() with a suitable comparison function. This cuts