快速排序和记忆问题 [英] Quick sort and memory problems

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

问题描述



我尝试实现快速排序。我按照第一个值对矢量进行排序。

10 2 3 4

9 3 5 6

10 4 5 6

必须是

9 3 5 6

10 2 3 4

10 4 5 6

前卫可能在500个向量上工作得很好,但我有一个Aborted(core

Dumped)尝试对22000个向量进行排序时出现错误消息。我以为

这是内存问题。所以在我得到矢量数组之后(一个是

少于枢轴而其他更大)并将第二个数组存储在

文件中,直到我准备好了使用它。它似乎不起作用。(

相同的错误信息)。

你有任何建议,

等待你的回复,

Bee。

Hi,
I try to implement quick sort. I sort vectors by their first value.
10 2 3 4
9 3 5 6
10 4 5 6
must be
9 3 5 6
10 2 3 4
10 4 5 6
The prog works great on maybe 500 vectors, but I have an "Aborted(core
Dumped)" error message when try to sort 22000 of vectors. I thought
it''s the memory problem. So after i get to arrays of vectors ( one is
less then pivot and other is bigger) and store the second array in the
file untill I''ll be ready to work with it. It seems doesn''t work.(
Same error message).
Do you have any suggestion,
Waiting for your reply,
Bee.

推荐答案

" Eva" < EV ******* @ hotmail.com>在消息中写道

news:e1 ************************** @ posting.google.c om ...
"Eva" <ev*******@hotmail.com> wrote in message
news:e1**************************@posting.google.c om...

我尝试实现快速排序。我按照他们的第一个价值对矢量进行排序。
10 2 3 4
9 3 5 6
10 4 5 6
必须是9 3 5 6
10 2 3 4
10 4 5 6
前卫在500个矢量上运行很好,但我有一个Aborted(core
Dumped)。尝试对22000个向量进行排序时出现错误消息。我以为这是记忆问题。所以在我得到向量数组之后(一个是
少于枢轴而另一个更大)并将第二个数组存储在
文件中,直到我将准备好使用它。它似乎不起作用。(
同样的错误信息)。
你有什么建议,
Hi,
I try to implement quick sort. I sort vectors by their first value.
10 2 3 4
9 3 5 6
10 4 5 6
must be
9 3 5 6
10 2 3 4
10 4 5 6
The prog works great on maybe 500 vectors, but I have an "Aborted(core
Dumped)" error message when try to sort 22000 of vectors. I thought
it''s the memory problem. So after i get to arrays of vectors ( one is
less then pivot and other is bigger) and store the second array in the
file untill I''ll be ready to work with it. It seems doesn''t work.(
Same error message).
Do you have any suggestion,




你为什么不是使用std :: sort或std :: stable_sort?这是作业吗?

这些载体有多大?它们是否包含整数?我不会怀疑

分配会失败,即使对于22,000个向量,除非它们很漂亮

大。


如果你真的对你的程序在做什么感到困惑,你可以随时使用调试器。然而,听起来你的程序很简单,如果你对它有一个很好的描述,其他人可以帮助你。


-

David Hilsee



Why aren''t you using std::sort or std::stable_sort? Is this for homework?
How big are these vectors? Do they contain ints? I wouldn''t suspect that
an allocation would fail, even for 22,000 vectors, unless they were pretty
big.

If you''re really confused as to what your program is doing, you could always
use a debugger. However, is sounds like your program is simple enough that
other folks could help you with it if you gave a good description of it.

--
David Hilsee


2004年8月6日14:27:27 -0700,Eva< ev ******* @ hotmail。 COM>写道:
On 6 Aug 2004 14:27:27 -0700, Eva <ev*******@hotmail.com> wrote:

我尝试实现快速排序。我按照他们的第一个价值对矢量进行排序。
10 2 3 4
9 3 5 6
10 4 5 6
必须是9 3 5 6
10 2 3 4
10 4 5 6
前卫在500个矢量上运行很好,但我有一个Aborted(core
Dumped)。尝试对22000个向量进行排序时出现错误消息。我以为这是记忆问题。所以在我得到向量数组之后(一个是
少于枢轴而另一个更大)并将第二个数组存储在
文件中,直到我将准备好使用它。它似乎不起作用。(
相同的错误信息)。
你有任何建议,
等待你的回复,
蜜蜂。
Hi,
I try to implement quick sort. I sort vectors by their first value.
10 2 3 4
9 3 5 6
10 4 5 6
must be
9 3 5 6
10 2 3 4
10 4 5 6
The prog works great on maybe 500 vectors, but I have an "Aborted(core
Dumped)" error message when try to sort 22000 of vectors. I thought
it''s the memory problem. So after i get to arrays of vectors ( one is
less then pivot and other is bigger) and store the second array in the
file untill I''ll be ready to work with it. It seems doesn''t work.(
Same error message).
Do you have any suggestion,
Waiting for your reply,
Bee.



是的,发布不起作用的代码。这里没有人是通灵者,除非你发布,否则我们不能用代码帮助你的b $ b。


john



Yes post the code that doesn''t work. Nobody here is psychic, we can''t help
with code unless you post it.

john

ev*******@hotmail.com (Eva)写道:
ev*******@hotmail.com (Eva) wrote:
我尝试实现快速排序。我按照它们的第一个值来对矢量进行排序。
这个程序在500个矢量上运行得很好,
但我有一个Aborted(core Dumped)。尝试排序时有错误消息
22000个向量。我认为这是记忆问题。
Hi, I try to implement quick sort. I sort vectors by their first
value.
The prog works great on maybe 500 vectors,
but I have an "Aborted(core Dumped)" error message when try to sort
22000 of vectors. I thought it''s the memory problem.




好​​的,这是一个疯狂的猜测,但是:你是否使用了递归的方式

实施快速排序?如果是这样,那么你可能会把你的程序堆栈弄得一团糟,因此你的程序会被你的操作系统杀死。

所以如果你想排序像22000个向量那么你不应该使用实际的

堆栈,而是使用堆栈类并将您的算法转换为一个大的
迭代循环(这可能很棘手)。


HTH



Ok, this is a wild guess, but: Are you using an recursive way of
implementing your quick-sort? If so, then you probably will mess up all
your programs stack and thus your program is killed by your OS.
So if you want to sort like 22000 vectors, you should not use the actual
stack, but rather use a stack class and turn your algorithm into a big
iteration loop (which can be tricky).

HTH


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

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