1. Node<E> Class
protected static class Node<E> {
 protected E data;
 protected Node<E> left;
 protected Node<E> right;
 
 public Node(E data) {
  this.data = data;
  left = null;
  right = null;
 }
 
 public String toString() {
  return data.toString();
 }
}
2. BinaryTree<E> Class
public class BinaryTree<E> {
	protected static class Node<E> {
		protected E data;
		protected Node<E> left;
		protected Node<E> right;
		public Node(E data) {
			this.data = data;
			left = null;
			right = null;
		}
		public String toString() {
			return data.toString();
		}
	}
	protected Node<E> root;
	public BinaryTree() {
		root = null;
	}
	protected BinaryTree(Node<E> root) {
		this.root = root;
	}
	public BinaryTree(E data, BinaryTree<E> leftTree, 
	 BinaryTree<E> rightTree) { 
	 root = new Node<E>(data);
	 if (leftTree != null) 
	 root.left = leftTree.root;
	 else 
	 root.left = null;
	 if (rightTree != null) 
	 root.right = rightTree.root; 
	 else 
	 root.right = null; 
	 
	 public BinaryTree<E> getLeftSubtree() { 
	 if (root != null && root.left != null) 
	 return new BinaryTree<E>(root.left); 
	 else 
	 return null 
	}
	public BinaryTree<E> getLeftSubtree() { 
	// getLeftSubtree()와 대칭적
	}
	}
}'Java > Java 알고리즘' 카테고리의 다른 글
| [알고리즘] 1-1. 버블 정렬 # (0) | 2022.06.27 | 
|---|---|
| [알고리즘] 1. 정렬 (1) | 2022.06.27 | 
| [알고리즘] 4-1. 검색 트리 (0) | 2022.03.03 | 
| [알고리즘] 3-5. 자바의 정렬 (0) | 2022.03.02 | 
| [알고리즘] 3-4. 분할 정복을 이용한 정렬 (3) (0) | 2022.03.02 |