• 几种基本的排序算法


           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;
            }

    感谢来访,共同学习!
  • 相关阅读:
    三栏布局
    两栏布局
    WEB前端开发笔试题(1)
    JavaScript document 对象
    设计一个有3个超链接的页面,单击这些链接时分别打开和关闭窗口以及关闭本身窗口。
    在窗体中有两个多选列表,用户可以从左侧列表中选择任意项,添加到右侧列表中。反之亦然。
    How and when: ridge regression with glmnet
    Fitting Bayesian Linear Mixed Models for continuous and binary data using Stan: A quick tutorial
    An Introduction to Stock Market Data Analysis with R (Part 1)
    Lesser known purrr tricks
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058810.html
Copyright © 2020-2023  润新知