-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
Copy pathTree.java
34 lines (27 loc) · 834 Bytes
/
Tree.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.bobocode.cs;
import java.util.function.Consumer;
public interface Tree<T extends Comparable<T>> {
/**
* insert an element
* @return true if element did not exist in the tree and was inserted successfully
*/
boolean insert(T element);
/**
* @return true if tree contains element
*/
boolean contains(T element);
/**
* @return number of elements in the tree
*/
int size();
/**
* @return max. number of transition between root node and any other node; 0 - if tree is empty or contains 1 element
*/
int depth();
/**
* traverse the tree in element's natural order
* @param consumer accepts ref. to node during traversing
*/
void inOrderTraversal(Consumer<T> consumer);
void preOrderTraversal(Consumer<T> consumer);
}