zoukankan      html  css  js  c++  java
  • 冒泡排序及折半查找

    冒泡排序:

                两层循环            

    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;

  • 相关阅读:
    红帽7 Shell编程
    红帽7 vim编辑器
    红帽7 管道符、重定向与环境变量
    红帽7 systemctl管理服务的启动、重启、停止、重载、查看状态等常用命令
    python 装饰器详解
    红帽7 常用系统命令
    转 JSON详解
    转 C# using 三种使用方式
    存储过程详解 转
    使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
  • 原文地址:https://www.cnblogs.com/UC0079/p/5491755.html
Copyright © 2011-2022 走看看