使用 java 的内置数组列表来创建堆应用程序?

using java's built in array-list to create heap application?

我制作了这个应用程序,尽管我是使用 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());
}


}

答案将是最大节点

20
10
7
8
12
6