C 中的 BinarySearch() 方法
BinarySearch() 根据列表是按数字分组、按字母分组还是按字符串分组来使用。它会找到元素的索引。
假设以下为我们的列表。
List<int> list = new List<int>(); list.Add(70); list.Add(150); list.Add(220); list.Add(250); list.Add(300);
现在,若要查看 250 所在的索引,请使用 BinarySearch() 方法
list.BinarySearch(250);
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
List<int> list = new List<int>();
list.Add(70);
list.Add(150);
list.Add(220);
list.Add(250);
list.Add(300);
int value = list.BinarySearch(250);
Console.WriteLine("Element 250 at Index: "+value);
}
}输出
Element 250 at Index: 3
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP