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

    }

}

 
看c++的数据结构时,觉得它上面的例子不正确,用c#来验证一下
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值