• 冒泡算法


    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

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    Java设计模式——单例模式
    重新学习MyBatis-逆向工程
    重新学习MyBatis(六)
    重新学习MyBatis(五)
    重新学习Mybatis(四)
    重新学习MyBatis(三)
    重新学习Mybatis(二)
    Java设计模式重新出发
    回归问题常用的损失函数总结
    Matlab绘图局部放大
  • 原文地址:https://www.cnblogs.com/plateFace/p/4148419.html
Copyright © 2020-2023  润新知