帮助排序 [英] help with sorting

查看:58
本文介绍了帮助排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,


我正在寻找一些见解:

给定两个排序的整数A和B数组,其中数组B有足够的

用于保存A和B内容的额外空间。合并数组A

和B一起使得结果是
$ b的排序组合$ b两个(不删除重复项),结果存在于B数组中。

我无法执行任何内存分配来解决问题。

应该考虑性能因素在你的

解决方案中考虑(所以强力方法不是一种选择)。这里有一些

示例数据可以帮助解释:


数组A:4 7 10 15 17

数组B:2 4 14 27 XXXXX


其中X''是阵列B中未使用的插槽。解决方案最终将是b / b
,B看起来像这样:


阵列B:2 4 4 7 10 14 15 17 27

使用以下函数原型:


void Merge( int * a,int na,int * b,int nb)

其中a和b指向两个数组,na和nb是
$ b $的数量每个数组中的b个元素。对于数组b,nb是使用的

元素的数量,而不是数组的大小。假设数组b足够大,可以保存a和b的内容。使用上面的示例数据na将是

5和nb将是4.


另外请指定算法的复杂程度

选择解决问题。


我的第一个想法是合并当然,虽然它需要你的
来执行额外的内存分配。这导致我在

地点合并排序。


你们有什么想法?有什么建议?代码并不是那么重要(我可以写b b)但是我正在寻找算法的帮助。

谢谢!

Hey guys,

I am looking for some insight:
Given two sorted arrays of integers A and B, where array B has enough
extra room in it to hold the contents of both A and B. Merge array A
and B together such that the result is the sorted combination of the
two (do not remove duplicates) and the result resides in the B array.
I cannot perform any memory allocations to solve the problem.
Performance considerations should be taken into account in your
solution (so brute force method is not an option). Here is some
example data to help explain:

Array A: 4 7 10 15 17
Array B: 2 4 14 27 X X X X X

Where the X''es are unused slots in array B. The solution would end up
with B looking like this:

Array B: 2 4 4 7 10 14 15 17 27
Using the following function prototype:

void Merge (int *a, int na, int *b, int nb)

Where a and b point to the two arrays, na and nb are the number of
elements in each array. For array b, nb is the number of used
elements, not the size of the array. Assume array b is large enough to
hold the contents of a and b. Using the above example data na would be
5 and nb would be 4.

Also please specify the order of complexity for the algorithm you
chose to solve the problem.

My first thoughts are merge sort of course, although it requires your
to perform additional memory allocation. This leads to me an in
place merge sort.

What do you guys thinks? Any suggestions? Code isn''t so important (i
can write that) but I am looking for help with the algorithm.
Thanks!

推荐答案



" ruel loehr" < RU ******* @ hotmail.com>在消息中写道

新闻:50 ************************** @ posting.google.c om ...

"ruel loehr" <ru*******@hotmail.com> wrote in message
news:50**************************@posting.google.c om...
嘿伙计们,

我正在寻找一些见解:
Hey guys,

I am looking for some insight:




这叫做合并排序。 />

怎么样而不是在这里询问你的家庭作业你要参加的课程

课程,阅读建议的材料,谷歌和反复试验?


Tom



This is called merge sorting.

How about instead of asking someone here todo your homework you attend
class, read the suggested material, google and trial-and-error?

Tom


文章< bD ****************** @ news04.bloor .is.net.cable.ro gers.com>,
******** @ iahu .ca 说...
In article <bD******************@news04.bloor.is.net.cable.ro gers.com>,
to********@iahu.ca says...

ruel loehr < RU ******* @ hotmail.com>在消息中写道
新闻:50 ************************** @ posting.google.c om ...

"ruel loehr" <ru*******@hotmail.com> wrote in message
news:50**************************@posting.google.c om...
嘿伙计们,

我正在寻找一些见解:
这叫做合并排序。
Hey guys,

I am looking for some insight:
This is called merge sorting.




哪个是在原文中提到。你剪了它,不管是什么原因。
怎么样而不是在这里问别人你做的功课你上课,阅读建议的材料,google和试用-and-error?



Which was mentioned in the original. You snipped it, for whatever
reason.
How about instead of asking someone here todo your homework you attend
class, read the suggested material, google and trial-and-error?




他正在征求关于如何实施的意见,并且还说

他没有找代码,但仅仅是关于如何实现它的建议。由于可疑的原因,你再次剪断了它。


话虽如此,这可能会在comp.programming中被问到

而不是在这里,因为它不是'真的语言有限。


无论哪种方式,你的回答再次粗鲁无缘无故。

-

Randy Howard

2reply删除FOOBAR



He was asking for opinions about how to implement, and also said that
he was not looking for the code, but merely suggestions about how to
implement it. You snipped that again, for suspect reasons.

That being said, this should probably be asked in comp.programming
instead of here, because it isn''t really language limited.

Either way, your response was once again rude for no apparent reason.
--
Randy Howard
2reply remove FOOBAR




" ruel loehr" < RU ******* @ hotmail.com>在消息中写道

新闻:50 ************************** @ posting.google.c om ...

"ruel loehr" <ru*******@hotmail.com> wrote in message
news:50**************************@posting.google.c om...
嘿伙计们,

我正在寻找一些见解:

给定两个排序的整数A和B数组,其中数组B有
足够多的空间来容纳A和B的内容。合并数组A
和B一起使得结果是
两个的排序组合(不删除重复项)和结果驻留在B
数组中。我无法执行任何内存分配来解决问题。
在您的解决方案中应考虑性能因素(因此无法使用强力方法)。这里有一些
示例数据可以帮助解释:

数组A:4 7 10 15 17
数组B:2 4 14 27 XXXXX

X''是阵列B中未使用的插槽。解决方案将结束
,B看起来像这样:

阵列B:2 4 4 7 10 14 15 17 27
使用以下函数原型:

void Merge(int * a,int na,int * b,int nb)

其中a和b指向两个数组na和nb是每个数组中
元素的数量。对于数组b,nb是使用的
元素的数量,而不是数组的大小。假设数组b足够大
来保存a和b的内容。使用上面的示例数据na,
为5,nb为4.

另外,请指定您选择解决问题的算法的复杂程度。 />
我的第一个想法是合并当然,虽然它需要
你执行额外的内存分配。这导致我在
地点合并排序。

你们有什么想法?有什么建议?代码并不是那么重要
(我可以写)但我正在寻找算法的帮助。

谢谢!
Hey guys,

I am looking for some insight:
Given two sorted arrays of integers A and B, where array B has enough extra room in it to hold the contents of both A and B. Merge array A
and B together such that the result is the sorted combination of the
two (do not remove duplicates) and the result resides in the B array. I cannot perform any memory allocations to solve the problem.
Performance considerations should be taken into account in your
solution (so brute force method is not an option). Here is some
example data to help explain:

Array A: 4 7 10 15 17
Array B: 2 4 14 27 X X X X X

Where the X''es are unused slots in array B. The solution would end up with B looking like this:

Array B: 2 4 4 7 10 14 15 17 27
Using the following function prototype:

void Merge (int *a, int na, int *b, int nb)

Where a and b point to the two arrays, na and nb are the number of
elements in each array. For array b, nb is the number of used
elements, not the size of the array. Assume array b is large enough to hold the contents of a and b. Using the above example data na would be 5 and nb would be 4.

Also please specify the order of complexity for the algorithm you
chose to solve the problem.

My first thoughts are merge sort of course, although it requires your to perform additional memory allocation. This leads to me an in
place merge sort.

What do you guys thinks? Any suggestions? Code isn''t so important (i can write that) but I am looking for help with the algorithm.
Thanks!




试试这个:

strcat(arrayB,arrayA);


这应该有效。

我们脾气暴躁的朋友说,在谷歌上搜索strcat

函数及其所需的标题。

请注意,一旦有这个数组,数组之间就没有空格了

已经完成了。

我很懒,所以我先添加一个空格数组,然后在第二个数组中添加



此函数返回第一个数组的名称作为新的组合

数组。

您可以正确编码以检查它是否适合猫''需要

的地方。

hth



Try this:
strcat(arrayB, arrayA);

That should work.
As our grumpy friend says, do a search on google for the strcat
function and the headers it needs.
Be aware that there is no white space etween the arrays once this has
been done.
I''m lazy so I just added an array of one whitespace first, then added
the second array.
This function returns the first array''s name as the new combined
array.
You can right code to check it will all fit before the cat'' takes
place.
hth


这篇关于帮助排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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