我是靠谱客的博主 安详小蝴蝶,这篇文章主要介绍算法导论 练习题 7.1-2,现在分享给大家,希望可以做个参考。

返回最后一个元素r 

int partition(int a[],int p,int r)
{
	int i=p-1;
	int x=a[r];
	bool flag=true;
	for(int j=p;j<r;j++)
	{
		if(a[j]<x || (a[j]==x && flag))
		{
			i++;
			int temp=a[i];
			a[i]=a[j];
			a[j]=temp;		
		}
		if(a[j]==x)
		{
			flag = !flag;
		}
	}
	int temp=a[i+1];
	a[i+1]=a[r];
	a[r]=temp;
	return i+1;
}


最后

以上就是安详小蝴蝶最近收集整理的关于算法导论 练习题 7.1-2的全部内容,更多相关算法导论内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(113)

评论列表共有 0 条评论

立即
投稿
返回
顶部