jGrasp Visualization
|
Key Concepts: |
import java.util.Random;
public class MyNode {
static Random rn = new Random ();
MyNode left, right;
int v;
String s;
MyNode (String ps, int pv) {
s = ps;
v = pv;
} // end String, int constructor
MyNode (String ps, int pv, int n) {
this (ps, pv);
addChildren (this, n);
} // end String, int, int constructor
void addChildren (MyNode m, int n) {
if (n == 0) return;
String sa = String.format ("%c", 'a' + rn.nextInt (26));
String sb = String.format ("%c", 'a' + rn.nextInt (26));
m.left = new MyNode (sa, rn.nextInt (100), n-1);
m.right = new MyNode (sb, rn.nextInt (100), n-1);
} // end method addChildren
public static void main (String [] args) {
MyNode root = new MyNode ("root", 123, 3);
} // end method main
} // end class MyNode