Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gdggfb committed Mar 24, 2018
1 parent b799536 commit b1bc84f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package cc.xkxk.learn.DataStructure2D;

import java.util.ArrayList;
import java.util.List;

public class RedBlackTree {
public static final boolean RED = false;
public static final boolean BLACK = true;
public Entry root;
public List<String> process = new ArrayList<>();

public static int size = 0;

public void remove(int key) {
Entry p = getEntry(key);
if (p == null)
return;

process.add("remove:" + key);
deleteEntry(p);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cc/xkxk/learn/DataStructure2D/StartDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void doDraw() {
public void actionPerformed(ActionEvent e) {
tree.put(r.nextInt(80));
if (RedBlackTree.size > 1) {
board.add(new TreeJpanel(tree.root));
board.add(new TreeJpanel(tree.root), 0);
board.revalidate();
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/cc/xkxk/learn/DataStructure2D/TreeJpanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public class TreeJpanel extends JPanel {
private Entry root = null;
private List<Graph> list = new ArrayList<>();

public TreeJpanel() {
setPreferredSize(new Dimension(width, height));
setLayout(null);
}

public TreeJpanel(Entry root) {
setPreferredSize(new Dimension(width, height));
setLayout(null);
Expand Down Expand Up @@ -72,7 +67,7 @@ public void countDepth(Entry node, Entry nodeP, boolean isLeft) {
countDepth(node.right, node, false);
}

public void drawNode(Entry node, int px, int py, boolean isLeft) {
public void collectNode(Entry node, int px, int py, boolean isLeft) {
int x, y, offset;
if (node == root) {
if (root.depthL > 6 || root.depthR > 6) {
Expand Down Expand Up @@ -116,8 +111,8 @@ public void drawNode(Entry node, int px, int py, boolean isLeft) {
list.add(new Graph(1, node.color ? Color.BLACK : Color.RED, x, y, diameter, diameter, null));
list.add(new Graph(3, Color.BLACK, x, y, 0, 0, String.valueOf(node.key)));

drawNode(node.left, x, y, true);
drawNode(node.right, x, y, false);
collectNode(node.left, x, y, true);
collectNode(node.right, x, y, false);
}

private void drawNode(Graphics2D graphics2D) {
Expand Down Expand Up @@ -156,7 +151,7 @@ protected void paintComponent(Graphics graphics) {

if (list.isEmpty()) {
countDepth(root, root, true);
drawNode(root, 0, 0, false);
collectNode(root, 0, 0, false);
} else {
drawNode(graphics2D);
}
Expand Down

0 comments on commit b1bc84f

Please sign in to comment.