标签:
冒泡排序:
两层循环
1.外层循环:循环趟数 n-1;
2.内层循环:两两比较的次数 n-2;
int[] shuzu = new int[10]{1,9,5,6,2,3,4,7,8,10 };
for (int i = 0; i < shuzu.length; i++)
{
for (int j = i; j < shuzu.length - 1; j++)
{
if (shuzu[i] > shuzu[j + 1])
{
int zhong = shuzu[i];
shuzu[i] = shuzu[j + 1];
shuzu[j + 1] = zhong;
}
}
}
//遍历数组
foreach (int a in shuzu)
{
console.writeline(a);
}
折半查找:
int[] a = new int[8] { 5,9,10,12,26,35,62,85};
int find = Convert.ToInt32(Console.ReadLine());
int kaiShi=0, jieShu=a.Length-1, zhongJian;
zhongJian = (kaiShi + jieShu) / 2;
标签:
原文地址:http://www.cnblogs.com/UC0079/p/5491755.html