0
我做了这个应用程序,但我使用内建的数组列表来创建它。这有可能是一堆吗?使用构建在数组列表中的java创建堆应用程序?
因为它的工作原理
https://gist.github.com/anonymous/d0e5c609045b8edbffcadd25080b45f8
我做了这个应用程序,但我使用内建的数组列表来创建它。这有可能是一堆吗?使用构建在数组列表中的java创建堆应用程序?
因为它的工作原理
https://gist.github.com/anonymous/d0e5c609045b8edbffcadd25080b45f8
我已经看到了你的代码。我不认为它会被视为堆。堆存储这种结构的数据
。
这是一个堆节点的模样
class hnode
{
int key;
hnode l;
hnode r;
hnode p; // parent
// constructor
hnode(int x){ key=x; l=r=p=null; }
}
预购
public void preorder(hnode temp)
{
if(temp!= null)
{
System.out.println(temp.key);
preorder(temp.l);
preorder(temp.r);
}
}
及主要方法
public class Heap {
public static void main(String[] args) {
maxheap obj= new maxheap();
obj.insert(12);
obj.insert(7);
obj.insert(6);
obj.insert(10);
obj.insert(8);
obj.insert(20);
obj.preorder(obj.rroot());
}
}
答案将是MAX NODE
20
10
7
8
12
6
如果这个代码工作正常,你应该提交我们的[代码审查(https://codereview.stackexchange.com/)的姐妹网站。 –
顺便说一句,我们没有关注本网站上的代码链接。因为链接中断。这个问题对其他人来说变得毫无用处。 –
在Wikipedia上查找二进制堆,并显示如何使用数组构建 –