using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
int sequence = 0;
List<int> ints = new List<int>()
{
9,832,32,2,1,10,4

};
while (true)
{
Console.WriteLine("请输入要查找的值:");
bool found = false;
int a = int.Parse(Console.ReadLine());
int mid = 0;
int i = 0;
int j = ints.Count - 1;
while (i < j)
{
if (i == j && ints[i] != a)
{
break;

}
mid = (i + j) / 2;
if (ints[mid] == a)
{
sequence = mid;
found = true;
break;
}
if (ints[mid] > a)
{
i = mid + 1;

}
else
{
j = mid - 1;

}

}
if (found)
{
Console.WriteLine("找到:" + a + " 在序号" + (sequence+1));
}
else
{
Console.WriteLine("没找到。");
}
}
Console.ReadKey();
}
}
}

最新文章

  1. Python面向对象(一)
  2. Tomca不生产日志 (原创帖,转载请注明出处)
  3. JS实现继承的几种方式
  4. C#双链表
  5. Oracle 多实例如何通过EM进行访问-portlist.ini
  6. 网卡及MAC和PHY的区别
  7. Flume学习——BasicTransactionSemantics
  8. Sunday字符串匹配算法
  9. ExtJS初接触 —— 了解 Ext Core
  10. onmouseover事件
  11. HashMap与HashTable的区别、HashMap与HashSet的关系
  12. JavaScript基础知识(正则表达式、字符串)
  13. lvs与nginx区别
  14. JS 跳出多重循环
  15. 安装splash
  16. 搞明白GOROOT,GOPATH,GOBIN,project目录
  17. 坑人的 Javascript 模块化编程 require.js
  18. “Interrupted by header callback: Server reports Content-Length”如何解决
  19. 在商城系统中使用设计模式----策略模式之在spring中使用策略模式
  20. 跨域请求:JSONP

热门文章

  1. [BZOJ5133][CodePlus2017年12月]白金元首与独舞
  2. fpga产生伪随机序列
  3. serf &#160;简单使用
  4. rmmod: can&#39;t change directory to &#39;/lib/modules&#39;: No such file or directory
  5. MySQL中创建用户与授权
  6. TableView刷新 局部刷新等
  7. nginx学习资源
  8. mysql事务之一:MySQL数据库事务隔离级别(Transaction Isolation Level)及锁的实现原理
  9. python下载指定页面的所有图片
  10. 前端学习---css基本知识