什么是字典顺序?

NDe*_*sai 13 sorting string lexicographic

字典顺序的确切含义是什么?它与字母顺序有何不同?

Ell*_*sch 21

字典顺序按字母顺序排列的.另一种是数字排序.考虑以下值,

1, 10, 2
Run Code Online (Sandbox Code Playgroud)

这些值按字典顺​​序排列.10以数字顺序出现在2之后,但是以"按字母顺序"顺序排在第2之前.

  • “字典顺序是字母顺序”。这并不*完全*正确。即使不涉及字母表,元组的排序也被描述为字典顺序,例如,根据字典顺序比较,(0,4,2) 小于(1,3,2)。请参阅此处的示例:https://en.wikipedia.org/wiki/Ordered_vector_space#Examples (6认同)
  • @NDesai No.如果第一个数字匹配,则比较第二个数字; 但它比较像`字符串' - 在"2"之前是"10",但在"10"之后是"111"(但在"1000"之后也是如此).因为"0"小于"1".词法排序将每个字符串中的字符比较为字符,而不是整数值. (3认同)
  • 常见的字母顺序是词典顺序的一个示例。 (2认同)

小智 19

字母顺序是一种特殊的字典顺序。术语词典通常指的是数学规则或排序。例如,这些包括从逻辑上证明排序是可能的。在维基百科上阅读有关词典顺序的更多信息

字母顺序包括在如何处理空格、大写字符、数字和标点符号方面不同的变体。纯粹主义者认为,允许 az 以外的字符使排序不是“字母顺序”,因此它必须属于更大的“词典”类。同样,维基百科有更多细节。

在计算机编程中,一个相关的问题是字典顺序ascii 代码顺序。在字典顺序中,大写“A”与小写“a”相邻排序。但是,在许多计算机语言中,默认的字符串比较将使用 ascii 代码。对于 ascii,所有大写字母都排在任何小写字母之前,这意味着“Z”将排在“a”之前。这有时称为ASCIIbetical order


Ham*_*ada 13

This simply means "dictionary order", i.e., the way in which words are ordered in a dictionary. If you were to determine which one of the two words would come before the other in a dictionary, you would compare the words letter by the letter starting from the first position. For example, the word "children" will appear before (and can be considered smaller) than the word "chill" because the first four letters of the two words are the same but the letter at the fifth position in "children" (i.e. d ) comes before (or is smaller than) the letter at the fifth position in "chill" (i.e. l ). Observe that lengthwise, the word "children" is bigger than "chill"但长度不是这里的标准。出于同样的原因,包含12345的数组将出现在包含1235的数组之前。(Deshmukh,OCP Java SE 11 程序员 I 1Z0815 学习指南 2019

  • “这”?阅读完整问题时,您的第一句话不明确。 (2认同)

Cod*_*r_H 11

词典顺序是指字典顺序。例如:在字典中,“ado”位于“adieu”之后,因为在英语字母系统中“o”位于“i”之后。这种排序不是基于字符串的长度,而是基于最小的字母首先出现。


ade*_*hox 5

我想添加一个与该术语的编程方面而不是数学方面更相关的答案。

字典顺序并不总是等同于“字典顺序”,至少这个定义在编程领域并不完整,而是指“基于多个标准的排序”。

例如,几乎在所有著名的编程语言中,都有用于对对象集合进行排序的标准工具,现在如果您想基于多个事物对集合进行排序怎么办?例如,假设您想首先根据价格然后根据受欢迎程度对某些商品进行排序。这是词典顺序的一个例子。

例如,在 Java (8+) 中,您可以执行以下操作:

// sorts items from the cheapest AND the most popular ones
// towards the most expensive AND the least popular ones.
Collections.sort(items,
    Comparator.comparing(Item::price)
   .thenComparing(Item::popularity)
   .reversed()
);
Run Code Online (Sandbox Code Playgroud)

Java 文档在解释“thenComaring()”方法时也使用这个术语来指代这种类型的排序:

返回一个字典顺序比较器与另一个比较器。