请帮帮我:Quicksort脱节的分区!!!? [英] Help me please: Quicksort disjointed partitions!!!?

查看:64
本文介绍了请帮帮我:Quicksort脱节的分区!!!?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字K,它是随机的,所以我应该找到一个阵列 的K个分区。

我有K-1个支点,它们也是随机的。

我必须重新组织阵列。



例如:



数组:5 2 4 6 1 3



pivot:k-1 = 2 - >随机Pivot 1:4和Pivot 2:5



所以我有3个分区。



我必须使用Quicksort和分区





< pre lang =c ++> void KQUICKSORT( int * list, int k, int p, int r)
{
int i = 0 ;
if (p< r)
{
int * L = KPARTITION(list,k,p,r);

for (i = 0 ; i< k; i ++)
{
KQUICKSORT(list,k,L [i],L [i + 1] - 1 );
}
}
}





我必须实现此代码,但我不知道有K分区...帮我

解决方案

然后回到你复制代码的地方,并在那里寻找。



我们不是来做你的功课! (而且你的导师可能知道大多数常用来源,所以如果不是你自己的工作,他会发现它......)



我自己写的,如果我是你 - 你会以这种方式学到更多。


I have a number, K, and it is random, so I should have K partitions of one array that they were find.
I have K-1 pivot, they are also random.
I must reorganize the array.

For example:

Array: 5 2 4 6 1 3

pivot: k-1=2 --> random Pivot 1: 4 and Pivot 2: 5

so I have 3 partitions.

I must use the Quicksort, and the Partition


void KQUICKSORT(int* list,int k,int p, int r)
{
 int i=0;
    if(p<r)
	 {
		int *L = KPARTITION(list, k, p, r);
		
		 for(i=0;i<k;i++)
		 {
		   KQUICKSORT(list, k, L[i],L[i+1]-1);
		 }
	 }
   }



I have to implement this code, but I don't have K partition... help me

解决方案

Then go back to where you copied that code from, and look for it there.

We aren't here to do your homework! (And your tutor is probably aware of most of the "usual sources" so he'll spot it if it isn't really your own work anyway...)

I'd write it myself, if I was you - you will learn a lot better that way.


这篇关于请帮帮我:Quicksort脱节的分区!!!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆