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

        }

    }

  • 相关阅读:
    AS3入门教程3流程控制
    C#里面的datagridview的使用
    .NET 2.0 WinForm Control DataGridView 数据绑定
    FLASH实用代码大全
    C#中回滚SQL语句
    AS3工程中的Loading的应用
    AS3类库资源大集合
    Flash(FLV)视频播放器开源代码大集合
    一位高手整理的IIS FAQ
    Flash ActionScript 3编程的总结
  • 原文地址:https://www.cnblogs.com/Safe3/p/1441579.html
Copyright © 2011-2022 走看看