我在 C# 中有一个非常大的字符串 ArrayList,并且定期在该 ArrayList 中搜索字符串。使用 ArrayList.IndexOf() 或 ArrayList.BinarySearch() 哪个更快?我可以对ArrayList进行排序。
最佳答案
该文档为您解释了一切。
The elements of the ArrayList must already be sorted in increasing value according to the sort order defined by the IComparable implementation; otherwise, the result might be incorrect.
This method is an O(log n) operation, where n is Count.
This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.
关于c# - 二元搜索和indexof 哪个更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34969585/