zoukankan      html  css  js  c++  java
  • 快速排序C#编程

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] a={3,2,5,1};
                QuickSort(a, 0, a.Length - 1);
                for (int i = 0; i < a.Length; i++)
                {
                    Console.WriteLine(a[i]);
                }
                Console.ReadLine();
            }
            
            public static void QuickSort(int[] array, int left, int right)
            {
                int origin_right = right;
                int origin_left = left;
                if (left>=right)
                {
                    return;
                }
                bool transfer = true;
                while (left<right)
                {
                    if (array[left]>array[right])
                    {
                        int tmp = array[left];
                        array[left] = array[right];
                        array[right] = tmp;
                        transfer = (transfer == true) ? false : true;
                    }
                    if (transfer)
                    {
                        right--;
                    }
                    else
                    {
                        left++;
                    }
                }
                QuickSort(array, origin_left, left - 1);
                QuickSort(array, right + 1, origin_right);
            }
        }
    }
  • 相关阅读:
    mysql新建用户的方法
    工具网站
    如何做好站内锚文本?
    js 创建对象与继承
    js tips
    js作用域链 js没有块级作用域
    css
    instanceof
    问题
    传递,引用副本传递
  • 原文地址:https://www.cnblogs.com/xinzehome/p/2849786.html
Copyright © 2011-2022 走看看