数组树...也许递归?

发布于 2024-10-06 10:45:30 字数 563 浏览 2 评论 0原文

我正在尝试递归地划分数组...我认为这就是所谓的哈哈...

例如,假设初始数组包含 50 个值,最高为 97,最低为 7...我想将该数组分成两部分,根据它们是否大于或小于整个集合的中间范围来划分它们。中频为 52...( (97+7)/2 ) 然后我想使用相同的方法来划分这两个数组,等等,理想情况下有一个程序可以重复这个过程任意次数......

Load Values into array1
Find Midrange 
For every value in array1{
       if value > midrange{
           assign value to ArrayHigh1}
       Else{ assign value to ArrayLow1}
}
Perform same thing on ArrayHigh1 and ArrayHigh2 

等等等等。

我很难弄清楚如何创建连续的数组数组(ArrayHigh2 3 4 等)

另外,我觉得必须有一种更简单的方法来做到这一点,但我现在想不出一个......

感谢您的帮助

I am trying to divide arrays recursively... I think that is what this would be called haha....

For instance, lets say the initial array contains 50 values the highest being 97 and the lowest being 7... I want to split this array into two, dividing them based on whether they are greater or lower than the midrange of the entire set. The midrange being 52...( (97+7)/2 )
Then I want to divide these two arrays using the same method and so on, ideally having a program that repeat this process an arbitrary number of times....

Load Values into array1
Find Midrange 
For every value in array1{
       if value > midrange{
           assign value to ArrayHigh1}
       Else{ assign value to ArrayLow1}
}
Perform same thing on ArrayHigh1 and ArrayHigh2 

Etc etc etc.

I'm having trouble figuring out how I would create the successive arrays (ArrayHigh2 3 4 etc)

Also, I feel like there must be an easier way to do this, but I cannot think of one at the moment...

Thanks for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恋你朝朝暮暮 2024-10-13 10:45:30

您似乎正在朝着 B-treeMerge-快速排序。 大量参考实现在线提供。

虽然一般而言,您可能会从阅读许多书籍中受益匪浅这里大家熟悉一下。

You seem to be working your way towards a B-tree or an implementation of Merge- or Quicksort. Plenty of reference implementations are available online.

Though speaking generally, you might benefit greatly from reading a book many here are familiar with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文