string 什么是字典序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45950646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:38:39  来源:igfitidea点击:

What is lexicographical order?

stringsortinglexicographic

提问by NDesai

What is the exact meaning of lexicographical order? How it is different from alphabetical order?

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

回答by Elliott Frisch

lexicographical order isalphabetical order. The other type is numerical ordering. Consider the following values,

字典序字母顺序。另一种类型是数字排序。考虑以下值,

1, 10, 2

Those values are in lexicographical order. 10 comes after 2 in numerical order, but 10 comes before 2 in "alphabetical" order.

这些值按字典顺​​序排列。10 按数字顺序在 2 之后,但 10 按“字母顺序”在 2 之前。

回答by Gordon Hopper

Alphabetical orderis a specific kind of lexicographical ordering. The term lexicographical often refers to the mathematical rules or sorting. These include, for example, proving logically that sorting is possible. Read more about lexicographical order on wikipedia

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

Alphabetical ordering includes variants that differ in how to handle spaces, uppercase characters, numerals, and punctuation. Purists believe that allowing characters other than a-z makes the sort not "alphabetic" and therefore it must fall in to the larger class of "lexicographic". Again, wikipediahas additional details.

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

In computer programming, a related question is dictionary orderor ascii codeorder. In dictionary order, the uppercase "A" sorts adjacent to lowercase "a". However, in many computer languages, the default string compare will use ascii codes. With ascii, all uppercase letters come before any lowercase letters, which means that that "Z" will sort before "a". This is sometimes called ASCIIbetical order.

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

回答by Hamza

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"but length is not the criteria here. For the same reason, an array containing 12345will appear before an array containing 1235. (Deshmukh, OCP Java SE 11 Programmer I 1Z0815 Study guide 2019)

这只是意味着“字典顺序”,即单词在字典中的排序方式。如果您要确定字典中两个单词中的哪个在另一个之前,您可以从第一个位置开始逐个字母比较单词。例如,单词“children”将出现在单词“chill”之前(并且可以被认为更小),因为这两个单词的前四个字母相同,但是“children”中第五个位置的字母(即 d ) 出现在(或小于)“chill”(即 l )中第五个位置的字母之前。纵向观察,“儿童”一词比“寒意”大但长度不是这里的标准。出于同样的原因,包含12345的数组将出现在包含1235的数组之前。(Deshmukh,OCP Java SE 11 程序员 I 1Z0815 学习指南 2019

回答by Coder_H

Lexicographical ordering means dictionary order. For ex: In dictionary 'ado' comes after 'adieu' because 'o' comes after 'i' in English alphabetic system. This ordering is not based on length of the string, but on the occurrence of the smallest letter first.

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