您的位置:首页 > 其它

算法学习笔记之快速排序

2013-08-27 12:02 155 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgorithmTest
{
class QuickSort
{
private int Partition ( int[] arr, int p, int r )
{
int x = arr[r];
int j = p -1;
for (int i = p; i < r; i++)
{
if (arr[i] <= x)
{
j++;
int temp1 = arr[j];
arr[j] = arr[i];
arr[i] = temp1;
}
}
int temp2 = arr[++j];
arr[j] = x;
arr[r] = temp2;
return j;
}

public void Quick_Sort ( int[] arr, int p, int r )
{
if (p < r)
{
int q = Partition(arr, p, r);
Quick_Sort(arr, p, q-1);
Quick_Sort(arr, q + 1, r);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: