zoukankan      html  css  js  c++  java
  • 冒泡算法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] array = { 1, 2, 3, 4, 5, 6 };
    
                bubble_sort(array, SortType.rise);
    
                for (int i = 0; i < array.Length; i++)
                {
                    Console.WriteLine(array[i]);
                }
    
    
                Console.ReadKey();
    
            }
    
    
            //冒泡算法
            static void bubble_sort(int[] unsorted, SortType type) 
            {
                if (type == SortType.rise)
                {
                    for (int i = 0; i < unsorted.Length; i++)
                    {
                        for (int j = i; j < unsorted.Length; j++)
                        {
                            if (unsorted[i] > unsorted[j])
                            {
                                int temp = unsorted[i];
                                unsorted[i] = unsorted[j];
                                unsorted[j] = temp;
                            }
                        }
                    }
                }
                else if(type == SortType.drop) 
                {
                    for (int i = 0; i < unsorted.Length; i++)
                    {
                        for (int j = i; j < unsorted.Length; j++)
                        {
                            if (unsorted[i] < unsorted[j])
                            {
                                int temp = unsorted[i];
                                unsorted[i] = unsorted[j];
                                unsorted[j] = temp;
                            }
                        }
                    }
                }
    
    
            }
    
        }
    
        public enum SortType 
        {
            drop,
            rise
        }
        
    
    }

    原文地址:http://www.cnblogs.com/kkun/archive/2011/11/23/2260280.html

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    文字标签和注释标签
    HTML文档的组成和标签的规范
    HTML概述
    javaWeb
    web开发的三层架构
    ASCII码表
    JDK的新特性
    Editplus的运行JAVA的配置
    Eclipse的断点调试
    Eclipse工作空间的基本配置
  • 原文地址:https://www.cnblogs.com/plateFace/p/4148419.html
Copyright © 2011-2022 走看看