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);
            }

        }

    }

  • 相关阅读:
    IE6 跟随滚动解决方法
    CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)
    [ConcurrencyCheck]并发检查
    centos7下修改docker工作目录
    kubernetes 1.14安装部署helm插件
    kubernetes 1.14安装部署EFK日志收集系统
    kubernetes 1.14安装部署dashboard
    kubernetes 1.14安装部署metrics-server插件
    calico客户端工具calicoctl
    centos7使用kubeadm安装部署kubernetes 1.14
  • 原文地址:https://www.cnblogs.com/Safe3/p/1441579.html
Copyright © 2011-2022 走看看