快排算法
来源:互联网 发布:微软phone软件 编辑:程序博客网 时间:2024/03/29 06:41
快排算法
// QuickSort implementation
static void QuickSort (ArrayList szArray, int nLower, int nUpper)
{
// Check for non-base case
if (nLower < nUpper)
{
// Split and sort partitions
int nSplit = Partition (szArray, nLower, nUpper);
QuickSort (szArray, nLower, nSplit - 1);
QuickSort (szArray, nSplit + 1, nUpper);
}
}
// QuickSort partition implementation
static int Partition (ArrayList szArray, int nLower, int nUpper)
{
// Pivot with first element
int nLeft = nLower + 1;
string szPivot = (string) szArray[nLower];
int nRight = nUpper;
// Partition array elements
string szSwap;
while (nLeft <= nRight)
{
// Find item out of place
while (nLeft <= nRight)
{
if (((string) szArray[nLeft]).CompareTo (szPivot) > 0)
break;
nLeft = nLeft + 1;
}
while (nLeft <= nRight)
{
if (((string) szArray[nRight]).CompareTo (szPivot) <= 0)
break;
nRight = nRight - 1;
}
// Swap values if necessary
if (nLeft < nRight)
{
szSwap = (string) szArray[nLeft];
szArray[nLeft] = szArray[nRight];
szArray[nRight] = szSwap;
nLeft = nLeft + 1;
nRight = nRight - 1;
}
}
// Move pivot element
szSwap = (string) szArray[nLower];
szArray[nLower] = szArray[nRight];
szArray[nRight] = szSwap;
return nRight;
}
- 算法----快排算法
- 快排算法
- 快排算法
- 快排算法
- 快排算法cmp
- 快排算法
- 算法导论--->快排
- 排序算法--快排
- 快排算法quickSort
- 快排算法
- 随机快排算法
- [算法]快排
- c#快排算法
- 算法 排序 快排
- 快排算法
- 大话算法-快排
- 算法-快排
- 快排算法
- asp.net页面生存周期
- asp.net2.0在绑定列格式化时间问题
- Windows 环境下的 PHP5 与 Apache 服务器的配置
- JS是怎样将1G硬盘变成120G(请勿用于非法途径)【荐】
- 获取汉字的拼音首字母
- 快排算法
- 利用System.Media来做声音提醒
- InstallShield内部库函数全集-中文版
- 利用XMLHTTP无刷新自动实时更新数据
- 画中画新闻
- 每个开发人员现在应该下载的十种必备工具
- .net2.0轻松判断NumLock、CapsLock、ScrollLock、Insert键的状态
- 如何防止XMLHttpRequest对象传回的中文数据中出现乱码?
- 如何循序渐进向DotNet架构师发展