class Item { Item left; Item right; int key; public Item(int key) { this.key = key; } } class Tree { Item top; public Tree() { this.top = null; } public void add(int key) { if (this.top == null) { this.top = new Item(key); } else { Item x = this.top; Item newItem = new Item(key); while(x != null) { if (x.key > key) { if (x.left == null) { x.left = newItem; break; } else { x = x.left; } } else { if (x.right == null) { x.right = newItem; break; } else { x = x.right; } } } } } public void preorderR(Item item) { System.out.print(item.key+" "); if (item.left != null) this.preorderR(item.left); if (item.right != null) this.preorderR(item.right); } public void preorder() { this.preorderR(this.top); System.out.println(); } public void inorderR(Item item) { if (item.left != null) this.inorderR(item.left); System.out.print(item.key+" "); if (item.right != null) this.inorderR(item.right); } public void inorder() { this.inorderR(this.top); System.out.println(); } public void postorderR(Item item) { if (item.left != null) this.postorderR(item.left); if (item.right != null) this.postorderR(item.right); System.out.print(item.key+" "); } public void postorder() { this.postorderR(this.top); System.out.println(); } public void searchR(Item item, int key) { if (item == null) return; System.out.print(item.key+" "); if (item.key > key) { this.searchR(item.left, key); } else { this.searchR(item.right, key); } } public void search(int key) { this.searchR(this.top, key); System.out.println(); } } public class Cv06Pr1{ public static void main(String[] args){ Tree tree = new Tree(); String cisla = VstupData.ctiString(); for(int i=0;i