2017-04-22 23 views
0

我做了這個應用程序,但我使用內建的數組列表來創建它。這有可能是一堆嗎?使用構建在數組列表中的java創建堆應用程序?

因爲它的工作原理

https://gist.github.com/anonymous/d0e5c609045b8edbffcadd25080b45f8

+0

如果這個代碼工作正常,你應該提交我們的[代碼審查(https://codereview.stackexchange.com/)的姐妹網站。 –

+2

順便說一句,我們沒有關注本網站上的代碼鏈接。因爲鏈接中斷。這個問題對其他人來說變得毫無用處。 –

+0

在Wikipedia上查找二進制堆,並顯示如何使用數組構建 –

回答

0

我已經看到了你的代碼。我不認爲它會被視爲堆。堆存儲這種結構的數據

See this image

這是一個堆節點的模樣

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 

Here is picture