惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
AWS News Blog
AWS News Blog
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Full Disclosure
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
About on SuperTechFans
J
Java Code Geeks
Jina AI
Jina AI
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
美团技术团队
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Latest news
Latest news
Vercel News
Vercel News
博客园 - 【当耐特】
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Microsoft Security Blog
Microsoft Security Blog
博客园_首页
S
Securelist
WordPress大学
WordPress大学
S
Secure Thoughts
博客园 - 聂微东
Cloudbric
Cloudbric
Help Net Security
Help Net Security
腾讯CDC
T
Threat Research - Cisco Blogs
T
Tor Project blog
L
LINUX DO - 热门话题
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
N
Netflix TechBlog - Medium
小众软件
小众软件
Cyberwarzone
Cyberwarzone
量子位
MyScale Blog
MyScale Blog
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
I
InfoQ
M
MIT News - Artificial intelligence

博客园 - 码 头

实测有效:Win11右键默认显示更多设置教程 netcore 并发锁 多线程中使用SemaphoreSlim HTML转义字符大全 .Net Core后台任务启停(BackgroundService) 常见的JavaScript的循环处理数据方法 Linux下.NET Core进程守护设置,解决SSH关闭后.NET Core服务无法访问的问题 记录 IIS 部署vue 项目步骤 AspNetCoreApi 跨域处理(CORS ) .NET CORE 使用Session报错:Session has not been configured for this application or request 小豆苗疫苗辅助搜索 日期函数(sql) 图片javascript缩小 c# DESEncrypt 加密、解密算法 汉字编码问题转换 MVC拦截器记录操作用户日志 最全的Resharper快捷键汇总 如何将数据库中的表导入到PowerDesigner中 修复IE9.0下PlaceHolder 属性问题js脚本 sql脚本查询日期时间段日期
二分法算法
码 头 · 2016-07-15 · via 博客园 - 码 头
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] iArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
            for (int i = 0; i < iArray.Length; i++)
                Console.Write(iArray[i] + ",");
            Console.WriteLine("请输入您要查找的数字:");
            int ikey = Convert.ToInt32(Console.ReadLine());
            Program bs = new Program();
            int iResult = bs.iBinarySearch(ikey, iArray);
            Console.WriteLine(iResult);
            Console.ReadLine();
            return;
        }

        public int iBinarySearch(int key, int[] iArray)
        {
            int iLeft = 0;
            int iRight = iArray.Length - 1;
            while (iLeft <= iRight)
            {
                int iMiddle = (iLeft + iRight) / 2;
                if (key == iArray[iMiddle])
                    return iMiddle;
                else if (key > iArray[iMiddle])
                    iLeft = iMiddle + 1;
                else
                    iRight = iMiddle - 1;
            }
            return -1;
        }
    }
}