From 2092ac5e3db02c7b549452b8d6b5ee6e5ff6c383 Mon Sep 17 00:00:00 2001 From: xiongk Date: Tue, 27 Mar 2018 20:57:42 +0800 Subject: [PATCH] update --- src/main/java/cc/xkxk/learn/dataStructure2D/StartFrame.java | 6 +++--- src/main/java/cc/xkxk/learn/dataStructure2D/TreeJpanel.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/cc/xkxk/learn/dataStructure2D/StartFrame.java b/src/main/java/cc/xkxk/learn/dataStructure2D/StartFrame.java index bd852c2..db4bdf3 100644 --- a/src/main/java/cc/xkxk/learn/dataStructure2D/StartFrame.java +++ b/src/main/java/cc/xkxk/learn/dataStructure2D/StartFrame.java @@ -31,12 +31,12 @@ public static void main(String[] args) { EventQueue.invokeLater(() -> new StartFrame().doDraw()); } - public void action(JTextField textField, JPanel board, RedBlackTree tree, int action) { + private void action(JTextField textField, JPanel board, RedBlackTree tree, int action) { doAction(textField, board, tree, action); textField.requestFocus(); } - public void doAction(JTextField textField, JPanel board, RedBlackTree tree, int action) { + private void doAction(JTextField textField, JPanel board, RedBlackTree tree, int action) { String value = textField.getText(); if (value == null || value.isEmpty()) { return; @@ -60,7 +60,7 @@ public void doAction(JTextField textField, JPanel board, RedBlackTree tree, int board.revalidate(); } - public void doDraw() { + private void doDraw() { JPanel board = createBoard(); JTextField textField = createTextField(); JPanel buttonPanel = createButtonPanel(board, textField); diff --git a/src/main/java/cc/xkxk/learn/dataStructure2D/TreeJpanel.java b/src/main/java/cc/xkxk/learn/dataStructure2D/TreeJpanel.java index 70f5ef2..f7bbee9 100644 --- a/src/main/java/cc/xkxk/learn/dataStructure2D/TreeJpanel.java +++ b/src/main/java/cc/xkxk/learn/dataStructure2D/TreeJpanel.java @@ -37,7 +37,7 @@ public TreeJpanel(Entry root, List process) { } private int countOffset(int depth) { - return (int) (distanceX * (depth + 1)); + return (int) (distanceX * (depth)); } public void depthCount(Entry node, Entry nodeP, boolean isLeft) { @@ -51,8 +51,10 @@ public void depthCount(Entry node, Entry nodeP, boolean isLeft) { if (is != (n == n.parent.left)) { if (is) { n.parent.depthR = n.parent.depthR + 1 + same; + System.out.println("key:" + node.key + "now:" + n.key + ",parentR:" + n.parent.depthR); } else { n.parent.depthL = n.parent.depthL + 1 + same; + System.out.println("key:" + node.key + "now:" + n.key + ",parentL:" + n.parent.depthR); } same = 0; } else { @@ -60,7 +62,6 @@ public void depthCount(Entry node, Entry nodeP, boolean isLeft) { } is = n == n.parent.left; } - depthCount(node.left, node, true); depthCount(node.right, node, false); }