非递归归并排序递归

2023-09-11 22:37:05 作者:发再多也深知上不了榜

能用英文有人解释如何做非递归归并排序工作?

Can someone explain in English how does Non-Recursive merge sort works ?

感谢

推荐答案

遍历的元素,使每一个相邻组的两个排序交换两个必要时。

Loop through the elements and make every adjacent group of two sorted by swapping the two when necessary.

现在,处理两组基(任何两个,最有可能的是相邻基团,但可以使用在第一和最后一个基团)将它们合并到一组被重复地选择从各组的最低值元素,直到所有的4元素是合并为一组4。现在,你什么都没有,但4组外加一个可能的剩余部分。使用周围的previous逻辑循环,再次做这一切,除了在4这一循环运行组这段时间的工作,直到有一个组。

Now, dealing with groups of two groups (any two, most likely adjacent groups, but you could use the first and last groups) merge them into one group be selecting the lowest valued element from each group repeatedly until all 4 elements are merged into a group of 4. Now, you have nothing but groups of 4 plus a possible remainder. Using a loop around the previous logic, do it all again except this time work in groups of 4. This loop runs until there is only one group.