我很難計算二進制搜索樹中節點之間的間距以供我分配。我有GUI實現,我可以手動創建樹或通過導入文本文件以及其他功能創建它。圖形二進制搜索樹 - 節點間距
在二叉搜索樹節點類中,有X和Y座標的getter和setter方法,我應該使用。現在,我已經開始工作了,但這是我在互聯網上散播的代碼混搭。例如,見this link。
的事情是,我做的不希望使用此代碼,因爲
- 這不是我和
- 但這並沒有利用提供的getter和setter方法。
我已被告知,在爲了得到間距右:
X座標成比例,其中該節點是在中序遍歷的過程中處理的順序號。
Y座標與節點的深度有關。
我有一個getHeight()
方法,它的工作原理和我認爲是相同的深度。
我希望有人能幫助我或指引我走向正確的方向。
UPDATE
對於Y座標?
int index = -1;
BinaryTreeNode nodes[];
int[] levels;
public void build(BinaryTreeNode node, int level)
{
if (node != null)
{
build(node.getLeftNode(), level+1);
index++;
nodes[index] = node;
levels[index] = level;
build(node.getRightNode(), level+1);
}
}
我很樂意幫忙,什麼是問題?你如何獲得按順序的遍歷計數? – biziclop 2011-03-03 23:42:19
問題是,如何在GUI中創建和顯示二叉查找樹時計算節點間距。我想我在我的問題中有一些漫不經心:) – 2011-03-04 00:13:35