当我们谈论排序时,什么是自然排序?

问题描述:

自然排序是什么意思.假设我有一个带有姓名、年龄和加入日期的 Employee 对象,按自然顺序排序?

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 ?

自然排序是一种字母数字排序,对人类来说似乎很自然.

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).

许多语言都有自然排序字符串的功能.但是,Employee 对语言来说太高级"了,你必须决定它对你意味着什么,让他们自然排序并创建相应的函数.

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.