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

  • 相关阅读:
    好多天没写了,郁闷
    昨天很受教育
    恼火的服务器
    欢迎访问我的博客网站
    体育产品论坛
    参考书目
    web2.0与数字标准
    用户产生内容与网站做内容
    Using x++ code reading data from csv file format
    Find out specified the folder for all the files
  • 原文地址:https://www.cnblogs.com/huyueping/p/3278062.html
Copyright © 2011-2022 走看看