• 函数——数组排序


    namespace 函数冒泡排序
    {
        class Program
        {
         
            static void Main(string[] args)
            {
                int[] b = new int[5] { 1,5,3,4,2};

                new Program().Array(b);   //数组b调用已经写好的Array函数用来排序

                for (int i = 0; i < b.Length; i++)
                {
                    Console.WriteLine(b[i]);
                }
                Console.ReadLine();
               
            } //主函数的花括号

    //Array函数
            public int[] Array(int[] a)
            {  
                int n = a.Length;
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n-i; j++)
                    {
                        int temp=0;
                        if(a[j-1]<a[j])
                        {
                            temp = a[j - 1];
                            a[j - 1] = a[j];
                            a[j] = temp;
                        }
                    }
                }
                return a;
            }
        }
    }

  • 相关阅读:
    Python Module_subprocess_子进程(程序调用)
    开机自启动Powershell脚本
    开机自启动Powershell脚本
    Powershell 音乐播放
    Powershell 音乐播放
    Powershell指令集_2
    Zabbix实战-简易教程(1)--总流程
    AWS上获取监控数据(EC2/RDS都支持)
    Grafana最新版本4.3.1安装(后端使用mysql)
    Haproxy实战(3)
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4420591.html
Copyright © 2020-2023  润新知