問題描述
我正在對由文本和數(shù)字組成的字符串進(jìn)行排序.我希望排序?qū)?shù)字部分排序為數(shù)字,而不是字母數(shù)字.
I'm sorting strings that are comprised of text and numbers. I want the sort to sort the number parts as numbers, not alphanumeric.
例如我想要:abc1def, ..., abc9def, abc10def
For example I want: abc1def, ..., abc9def, abc10def
代替:abc10def, abc1def, ..., abc9def
instead of: abc10def, abc1def, ..., abc9def
有誰知道這方面的算法(特別是在 C++ 中)
Does anyone know an algorithm for this (in particular in c++)
謝謝
推薦答案
我問了 這個確切的問題(盡管在 Java 中) 并指向 http://www.davekoelle.com/alphanum.html,其中有一個算法及其多種語言的實現(xiàn).
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.
這篇關(guān)于如何在 C++ 中實現(xiàn)自然排序算法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!