zoukankan      html  css  js  c++  java
  • 几种基本的排序算法

           protected int[] bubbleUp(int[] Array)//冒泡排序
            {
                for (int i = 0; i < Array.Length-1; i++)//要冒泡次数
                {
                    for (int j = 0; j < Array.Length-1-i; j++)//每次冒泡具体比较过程
                    {
                        if (Array[j] < Array[j + 1])
                        {
                            int temp = Array[j + 1];
                            Array[j + 1] = Array[j];
                            Array[j] = temp;
                        }
                    }
                }
                return Array;
            }
            public int[] SelectionSorter(int[] list)//选择排序
            {
                int min;
                for (int i = 0; i < list.Length - 1; i++)
                {
                    min = i;
                    for (int j = i + 1; j < list.Length; j++ )              
                    {
                        if (list[j] < list[min])
                            min = j;
                    }
                    int temp = list[min];
                    list[min] = list;
                    list = temp;
                }
                return list;
            }
            public int[] InsertionSorter(int[] list)// 插入排序
            {
                for (int i = 1; i < list.Length; i++)
                {
                    int temp = list;
                    int j = i;
                    while ((j > 0) && (list[j - 1] > temp))
                    {
                        list[j] = list[j - 1];
                        --j;
                    }
                    list[j] = temp;
                }
                return list;
            }
            public int[] ShellSorter(int[] list)//希尔排序
            {
                int inc;
                for (inc = 1; inc <= list.Length / 9; inc = 3 * inc + 1) ;
                for (; inc > 0; inc /= 3)
                {
                    for (int i = inc + 1; i <= list.Length; i += inc)
                    {
                        int t = list[i - 1];
                        int j = i;
                        while ((j > inc) && (list[j - inc - 1] > t))
                        {
                            list[j - 1] = list[j - inc - 1];
                            j -= inc;
                        }
                        list[j - 1] = t;
                    }
                }
                return list;
            }

    感谢来访,共同学习!
  • 相关阅读:
    mupdf-将pdf转png图片
    Teamcenter二次开发-客户端JAVA开发挂菜单HelloWorld例子
    SqlServer-导入excel表格数据
    PDFlib创建pdf文档
    计算机网络基础知识总结-转载
    到底什么是架构?回答你关于软件架构的所有疑惑。
    SQL语句-获得表的字段数量
    vue3.0---watch使用方法
    小程序picker自定义三级联动
    无法加载文件 D:Program Files odejs ode_globalvue.ps1,因为在此系统上禁止运行脚本。有关详细信息
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058810.html
Copyright © 2011-2022 走看看