How to implement a natural sort algorithm in c++?

Will picture Will · Mar 13, 2009 · Viewed 12.7k times · Source

I'm sorting strings that are comprised of text and numbers. I want the sort to sort the number parts as numbers, not alphanumeric.

For example I want: abc1def, ..., abc9def, abc10def

instead of: abc10def, abc1def, ..., abc9def

Does anyone know an algorithm for this (in particular in c++)

Thanks

Answer

Paul Tomblin picture Paul Tomblin · Mar 13, 2009

I asked this exact question (although in Java) and got pointed to http://www.davekoelle.com/alphanum.html which has an algorithm and implementations of it in many languages.