zoukankan      html  css  js  c++  java
  • 排序 冒泡排序法

    原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

    using System;//冒泡排序

    namespace sorts
    {
       public class Class3
        {
           public static void Main()
           {
               int[] a=new int[]{2,8,4,6,9,4};
               BubbleSort arr=new BubbleSort();
               arr.Sort(a);
               for(int i=0;i<a.Length;i++)
                   Console.Write("{0} ",a[i]);
               Console.WriteLine();
               Console.ReadLine();
           }

        }
        public class BubbleSort
        {
            public void Sort(int[] arr)
            {
                for (int i = 0; i < arr.Length; i++)
                    for (int j = 0; j < arr.Length-i- 1; j++)
                    {
                        if (arr[j] > arr[j + 1])
                        {
                            int temp = arr[j + 1];
                            arr[j + 1] = arr[j];
                            arr[j] = temp;
                        }
                    }
            }
        }
    }

  • 相关阅读:
    Java 和因特网
    永久性
    在计算机编程中,一个基本的概念就是同时对多个任务加以控制
    违例控制:解决错误
    清除时的困境:由谁负责清除?
    集合库与方便使用集合
    单根结构
    集合与继承器
    对象的创建和存在时间
    抽象的基础类和接口
  • 原文地址:https://www.cnblogs.com/handboy/p/7153252.html
Copyright © 2011-2022 走看看