zoukankan      html  css  js  c++  java
  • C#冒泡排序和直接插入排序

    /// <summary>
            /// 冒泡排序
            /// </summary>
            public static void Mainsdfdrt()
            {
                bool B;
                int[] Array = new int[] { 5, 4, 3, 2, 1 };
                for (int i = 1; i < Array.Length; i++)
                {
                    B = false;
                    for (int j = Array.Length-1; j >= i ; j--)
                    {
                        int R;
                        if (Array[j-1]>Array[j])
                        {
                            R = Array[j - 1];
                            Array[j - 1] = Array[j];
                            Array[j] = R;
                            B = true;
                        }
                    }
                    if (!B)
                    {
                        break;
                    }
                }

                for (int i = 0; i < Array.Length; i++)
                {
                    Console.WriteLine(Array[i]);
                }

                Console.ReadLine();
            }

    /// <summary>
            /// 直接插入排序法
            /// </summary>
            public static void Main()
            {
                int[] R = new int[] { 5, 4, 3, 2, 1};
                //int i, j;
                for (int i = 1; i < R.Length; i++)
                {
                    if (R[i] < R[i - 1])
                    {
                        int T = R[i];                    
                        int j;

                        for (j = i - 1; j >= 0 && T < R[j]; j--)
                        {
                            R[j + 1] = R[j];
                        }
                        R[j + 1] = T;
                    }
                }

                for (int i = 0; i < R.Length; i++)
                {
                    Console.WriteLine(R[i]);
                }
                Console.ReadLine();   
            }

  • 相关阅读:
    图书馆业务制图
    单元测试(输入一个数组和它的大小,输出这个数组中最大子数组的和)
    build to win读后感
    小学四则运算
    微信公众平台具体方案和人员分工
    问卷调查结果剖析
    题目确定与需求分析
    课程介绍与团队简介
    网站LOGO以及网页样式
    C Sharp进行网站信息抽取与小型内部搜索引擎的讲解
  • 原文地址:https://www.cnblogs.com/huyueping/p/3278062.html
Copyright © 2011-2022 走看看