It is also called Natural sort order.
"It's hard to find information on natural sorting"-Jeff Atwood on Coding Horror.
And it seems true today as the Wikipedia entry seems pretty bare.
The main difference is that Definition 1 allows decimals while Definition 2 does not. For example I have the list ["t8.1", "t8.11", "t8.2", "t7.2", "t7.11"].
Definition 1 would yeild: ["t7.11", "t7.2", "t8.1", "t8.11", "t8.2"].
Definition 2 would yeild: ["t7.2", "t7.11", "t8.1", "t8.2", "t8.11"].
Perl follows definition 1 (which is where I found it.
MATLAB uses definition 2 for non-version numbers.
Dave Koelle implements definition 1 for his examples but says it's a 'glitch' and thus supporting definition 2 as correct. In most the linked code, the code treats '.' as a string but what if it was a decimal in a numeric substring? Dave Koelle notes this as a glitch by saying "There is currently a glitch when it comes to periods/decimal points - specifically, periods are treated only as strings, not as decimal points.".
To me, the word numeric would imply decimals but in practice it seems that this is not the case unless specifically noted to include decimals.
What does Alphanumberic/Natural Order Sort mean exactly without additional qualifiers? For example: In "Natural Order Sort with decimals", "with decimals" would be an additional qualifiers. Which definition is correct for "Natural Order Sort"?
Asked By : Paul Totzke
Answered By : Evil
Alphanumeric sort means that every character is compared according to ascii representation.
Natural sort treats consecutive digits as one chatacter, so actually compares as integer. There is no place for decimals, but when you compare two numbers in the form $X.Y > W.Z$ it looks like decimal compare.
So what does "natural sort does not compare decimals" really mean?
The example above is just coincidence, like reading month.day as float and sorting will give good order, but adding and subtracting is not defined. Same here, "-" will not be identified as part of decimal, so comparison will be shifted. The separator might be given as anything, but will change results when inconsistent.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/60530
0 comments:
Post a Comment
Let us know your responses and feedback