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;

  • 相关阅读:
    printf函数实现的深入剖析
    rhel/centos播放mp3文件
    GRUB(GRand Unified Boot loader)引导加载程序
    NAT DHCP WWW rc.local
    论文 毕业设计 相关 用语 评语
    Linux禁止单用户模式(single)来增强系统安全
    Kernel command using Linux system calls
    GNU-ld链接脚本浅析
    AT&T汇编心得之间接寻址和LEA指令
    Linux 汇编语言开发指南
  • 原文地址:https://www.cnblogs.com/UC0079/p/5491755.html
Copyright © 2011-2022 走看看