简体   繁体   English

Java Mergesort实现出现stackoverflow错误

[英]Java Mergesort Implementation having a stackoverflow error

I'm not quite sure why my merge sort implementation is getting a stackoverflow error. 我不太确定为什么我的归类排序实现会出现stackoverflow错误。 I've reviewed the code multiple times but I'm not getting why this is happening. 我已经多次审查了代码,但是我不知道为什么会这样。 I tried debugging but have had trouble understanding why the values 0 and 4 (the first and last index of array) never change when I walk through the code. 我尝试调试,但在理解为什么遍历代码时为何值0和4(数组的第一个和最后一个索引)从不改变时遇到了麻烦。 And then finally it throws the stack overflow error. 最后,它引发了堆栈溢出错误。

The first recursive call to mergesort (line 17?) should use "start, mid", not "start, end". 对mergesort的第一个递归调用(第17行?)应使用“开始,中间”,而不是“开始,结束”。 That puts you in an endless loop, so you eventually run out of stack. 这使您陷入无休止的循环,因此最终耗尽了堆栈。

Trust your debugger. 相信您的调试器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM