Skip to main content
Clarifying question so people don't think I am simply asking how to implement a binary tree.
Source Link
aCarella
  • 329
  • 1
  • 2
  • 8

Class structure: How should a binary tree and it's node class be implemented in Java in terms of class files?

This may seem trivial, but I wanted some input. In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTree class, or should it be a default class in the same class file as the BinaryTree class?


First Example: Node is in separate class file

BinaryTree.java

public class BinaryTree {
    ...
}

BinaryTreeNode.java

public class BinaryTreeNode {
    ...
}

Second Example: Node class is default class in same class file

BinaryTree.java
public class BinaryTree {
    ....
}
class BinaryTreeNode {
    ...
}

I almost never see the use case for putting more than one class inside of the same class file, but this might be the first time I see it being useful. Does this make sense, or would this be considered sloppy code?

How should a binary tree and it's node class be implemented in Java?

This may seem trivial, but I wanted some input. In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTree class, or should it be a default class in the same class file as the BinaryTree class?


First Example: Node is in separate class file

BinaryTree.java

public class BinaryTree {
    ...
}

BinaryTreeNode.java

public class BinaryTreeNode {
    ...
}

Second Example: Node class is default class in same class file

BinaryTree.java
public class BinaryTree {
    ....
}
class BinaryTreeNode {
    ...
}

I almost never see the use case for putting more than one class inside of the same class file, but this might be the first time I see it being useful. Does this make sense, or would this be considered sloppy code?

Class structure: How should a binary tree and it's node class be implemented in Java in terms of class files?

In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTree class, or should it be a default class in the same class file as the BinaryTree class?


First Example: Node is in separate class file

BinaryTree.java

public class BinaryTree {
    ...
}

BinaryTreeNode.java

public class BinaryTreeNode {
    ...
}

Second Example: Node class is default class in same class file

BinaryTree.java
public class BinaryTree {
    ....
}
class BinaryTreeNode {
    ...
}

I almost never see the use case for putting more than one class inside of the same class file, but this might be the first time I see it being useful. Does this make sense, or would this be considered sloppy code?

Source Link
aCarella
  • 329
  • 1
  • 2
  • 8

How should a binary tree and it's node class be implemented in Java?

This may seem trivial, but I wanted some input. In implementing a binary tree in Java, should the node class be a separate class file independent of the BinaryTree class, or should it be a default class in the same class file as the BinaryTree class?


First Example: Node is in separate class file

BinaryTree.java

public class BinaryTree {
    ...
}

BinaryTreeNode.java

public class BinaryTreeNode {
    ...
}

Second Example: Node class is default class in same class file

BinaryTree.java
public class BinaryTree {
    ....
}
class BinaryTreeNode {
    ...
}

I almost never see the use case for putting more than one class inside of the same class file, but this might be the first time I see it being useful. Does this make sense, or would this be considered sloppy code?