• 快速排序算法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);
            }

        }

    }

  • 相关阅读:
    [HAOI2008]硬币购物
    [SCOI2005]骑士精神
    [ZJOI2007]最大半联通子图
    [HAOI2007]反素数
    [SCOI2005]繁忙的都市
    小凯的疑惑
    5月16日vj题解
    周六题目前四题详解
    Codeforces Round #629 (Div. 3)做题记录
    Codeforces Round #570 (Div. 3) B. Equalize Prices
  • 原文地址:https://www.cnblogs.com/Safe3/p/1441579.html
Copyright © 2020-2023  润新知