【问题标题】:Can anyone tell how to program a Binary Search in Windows Forms pls?谁能告诉如何在 Windows 窗体中编写二进制搜索?
【发布时间】:2015-07-28 20:36:52
【问题描述】:

有谁知道如何在 Windows 窗体应用程序 (C#) 中进行二进制搜索而不执行插入部分?我需要从 allItems 列表中搜索。

【问题讨论】:

标签: c# .net winforms visual-studio binary-search


【解决方案1】:

试试这个它显示索引输出:-

using System;
using System.Collections.Generic;
namespace BinarySearchmethod
{
    class AKSHAY
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>() { "A", "B", "C", "D", "E", "F", "G" };
            int index1 = list.BinarySearch("C");
            Console.WriteLine("Index 1: {0}", index1);
            int index2 = list.BinarySearch("F");
            Console.WriteLine("Index 2 : {0} ", index2);
            int index3 = list.BinarySearch("H");
            Console.WriteLine("Index 3 : {0} ", index3); 
            // wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
    }
}

输出:-

Binary Search Tree Implementation in C#

【讨论】:

  • 知道如何不进行硬编码吗?我的意思是,我需要在文本框中插入一串单词并在列表框中显示结果(这是一串单词)。谢谢
【解决方案2】:

看看 List 类,它有一个返回索引的二分查找方法。 https://msdn.microsoft.com/en-us/library/w4e7fxsh%28v=vs.110%29.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    相关资源
    最近更新 更多