Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node {
- private int data;
- public int getData() {
- return data;
- }
- private Node left;
- private Node right;
- public Node(int d, Node l, Node r) {
- data = d;
- left = l;
- right = r;
- }
- // Deep copy constructor
- public Node(Node o) {
- if (o == null) return;
- this.data = o.data;
- if (o.left != null) this.left = new Node(o.left);
- if (o.right != null) this.right = new Node(o.right);
- }
- public String toString() {
- String l = (left == null) ? "" : (left + ", ");
- String r = (right == null) ? "" : (", " + right);
- return l + data + r;
- }
- public void insert(int d) {
- if (data == d) return;
- if (data > d) {
- if (left == null)
- left = new Node(d, null, null);
- else
- left.insert(d);
- } else {
- if (right == null)
- right = new Node(d, null, null);
- else
- right.insert(d);
- }
- }
- public boolean contains(int d) {
- if (data == d) return true;
- if (data > d)
- return (left == null) ? false : left.contains(d);
- return (right == null) ? false : right.contains(d);
- }
- public boolean equals(Node o) {
- boolean result = false;
- if (o != null) {
- if (o.left == left && o.right == right && o.data == data) {
- result = true;
- }
- }
- return result;
- }
- public List<Integer> toList() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement