what is natural ordering when we talk about sortin

2019-01-05 03:11发布

What is meant by natural ordering . Suppose I have an Employee object with name , age and date of joining , sorting by what is natural ordering ?

标签: sorting
4条回答
We Are One
2楼-- · 2019-01-05 03:24

For Java, The ordering provided by the Comparable interface is called the natural ordering, so the Comparator interface provides, so to speak, an unnatural ordering.

查看更多
beautiful°
3楼-- · 2019-01-05 03:25

If someone like me found himself reading the following article:

https://www.copterlabs.com/natural-sorting-in-mysql/

(which by the way is really useful), beware it because that's another method of sorting.

A correct natural sorting algorithm states that you order alphabetically but when you encounter a digit you will order that digit and all the subsequent digits as a single character.

Natural sorting has nothing to do with sorting by string length first, and then alphabetically when two strings have the same length. Though the article I linked is interesting, don't make the mistake I made and think that that's the correct way to sort naturally.

查看更多
做自己的国王
4楼-- · 2019-01-05 03:27

Natural ordering is a kind of alphanumerical sort which seems natural to humans.

In a classical alphanumerical sort we will have something like :

1 10 11 12 2 20 21 3 4 5 6 7

If you're using Natural ordering, it will be :

1 2 3 4 5 6 7 10 11 12 20 21

Depending on the language, natural ordering sometimes ignore Capital letters and accentuated one (ie all accentuated letters are treated like their non-accentuated counterpart).

Many languages have a function to order a String naturally. However, an Employee is too "high level" for the language, you must decide what it means for you to order them naturally and create the according function.

In my point of view, ordering Employee will start by ordering them by name using a natural sort, then age and finally date of joining.

According to statistics there are two types of categorical variables. Variables having categories without a numerical ordering (nominal) and those which do have ordered categories (ordinal). The example of an Employee's name, age and date of joining is actually considered a nominal variable so there can be no sorting by natural ordering. Natural ordering could exist for example in age had you categorized it in levels of child, teenager, adult, in which one can observe an ascending type of sorting.

查看更多
淡お忘
5楼-- · 2019-01-05 03:30

For strings containing numbers it means 1,2,3,4,5,6,7,8,9,10,11 instead of 1,10,11,2,3,4,5,6,7,8,9

查看更多
登录 后发表回答