zoukankan      html  css  js  c++  java
  • 快速排序算法c#

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Sort
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                
    int[] array = 8,22,9,12,4,5,2,1,1};
                QuickSort(array, 
    0, array.Length - 1);
                
    for (int i = 0; i < array.Length; i++)
                
    {
                    Console.WriteLine(array[i]);
                }

                Console.Read();
            }


            
    //快速排序从大到小
            private static void QuickSort(int[] sort, int start, int end)
            
    {
                
    int i = start;
                
    int j = end + 1;

               
                
    int val = sort[i];
                
    do
                
    {
                    
    do
                    
    {
                        i
    ++;
                    }
     while (sort[i] > val && i < end);

                    
    do
                    
    {
                        j
    --;
                    }
     while (sort[j] < val && j > start);

                    
    if (i < j)
                    
    {
                        
    int temp;
                        temp 
    = sort[i]; sort[i] = sort[j]; sort[j] = temp;
                    }

                }
     while (i < j);

                sort[start] 
    = sort[j]; sort[j] = val;
                
    if (j > start + 1) QuickSort(sort, start, j - 1);
                
    if (j < end - 1) QuickSort(sort, j + 1, end);
            }

        }

    }

  • 相关阅读:
    JS——switch case
    JS——“==”与“===”
    C#——枚举格式转换与比较
    XML——读与写
    SQl基本操作——try catch
    JS——indexOf replace search
    C#——数据库的访问
    SQL基本操作——存储过程
    C#——设置开机启动
    C#——计时器的操作
  • 原文地址:https://www.cnblogs.com/Safe3/p/1441579.html
Copyright © 2011-2022 走看看