首页 > 编程语言 > 详细

【指针数组快速排序】

时间:2019-12-25 13:54:04      阅读:81      评论:0      收藏:0      [点我收藏+]

/*************************************************************************
** 函数名称: QuickSort
** 功能描述: 指针数组快速排序
** 输入参数: char *array[] 指针数组
** int left 起始位置
** int right 结束位置
** 输出参数:
** 返回结果:
**
************************************************************************/
/* 指针数组快速排序 */
int QuickSort(char *array[], int left, int right)
{
if(left>right)
return 0;

/* 取最左边的值为pivot(基准)*/
int i = left;
int j = right;
char *pivot = array[left];
while( i<j )
{
while((i<j) && ((strncmp(pivot, array[j], LEN_MCHNO)<0) || (strncmp(pivot, array[j], LEN_MCHNO)==0)))
j--;

if(i<j )
array[i++] = array[j];

while((i<j) && ((strncmp(pivot, array[i], LEN_MCHNO)>0) || (strncmp(pivot, array[i], LEN_MCHNO)==0)))
i++;

if(i<j)
array[j--]=array[i];
}
array[j] = pivot;
QuickSort(array,left,i-1);
QuickSort(array,i+1,right);
}

【指针数组快速排序】

原文:https://www.cnblogs.com/Yloon/p/12096070.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!