• 冒泡算法


    C#

    static void Bubble()
    {
        int temp = 0;
       List<int> list = new List<int>() { 72, 54, 59, 30, 31, 78, 2, 77, 82, 72 };
        for (int i = list.Count; i > 1; i--)
        {
            for (int j = 0; j < i - 1; j++)
            {
                if (list[j] > list[j + 1])
                {
                    temp = list[j];
                    list[j] = list[j + 1];
                    list[j + 1] = temp;
                }
            }
        }
    }
     
    javascript
     

    function MaoPaoSort()    

    {        

      var temp;        

      var arr = [5, 4, 3, 2, 1];        

      var flag = true;        

      for (var i = arr.length; i > 1; i--)        

       {            

        if (flag)

        {                

           flag = false;                

           for (var j = 0; j < i - 1; j++)

          {                    

             if (arr[j] > arr[j + 1])

            {                        

              temp = arr[j];                        

              arr[j] = arr[j + 1];                        

              arr[j + 1] = temp;

                              flag = true;                    

            }                

          }            

        }        

       }

            alert(arr.join(' , '))    

    }

  • 相关阅读:
    JAVA自学笔记13
    非常不错的一款打字代码效果
    诡异的python文件
    Linux 虚拟机 docker 上 搭建 python 机器学习 平台
    git无法pull仓库: refusing to merge unrelated histories
    Python
    28 Jupyter Notebook tips, tricks, and shortcuts[Re-post]
    What is the best way to calculate a checksum for a file that is on my machine?
    Building MAPI Applications on 32-Bit and 64-Bit Platforms
    Linux 查看进程 关闭进程
  • 原文地址:https://www.cnblogs.com/itjeff/p/3539736.html
Copyright © 2020-2023  润新知