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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crateBinaryTree;
/// The create function is for creating a binary tree with a head, left, and right
///
/// Example:
///
/// ```
/// use algotrees::binary_trees::{initialize, prelude::BinaryTree};
///
/// let tree: BinaryTree<i32> = initialize::create(
/// 5i32,
/// Some(Box::new(initialize::create(3, None, None))),
/// Some(Box::new(initialize::create(7, None, None))),
/// );
///
/// assert_eq!(
/// tree,
/// BinaryTree {
/// head: 5,
/// left: Some(Box::new(BinaryTree {
/// head: 3,
/// left: None,
/// right: None
/// })),
/// right: Some(Box::new(BinaryTree {
/// head: 7,
/// left: None,
/// right: None
/// }))
/// }
/// )
///
/// ```
/*
pub fn from<T>(mut vec: Vec<Vec<T>>) -> BinaryTree<T>
where
T: Default + Copy,
{
// [1, 2, 3, 5, 7, 9] -> [[1], [2, 3], [5, 7], [9, None]]
// 1
// / \
// 2 3
// / \ / \
// 5 7 9 None
}
*/
/// Creates an empty binary tree
/// Will create the head with the default value of the type ie. 0 for i32
///
/// Example:
///
/// ```
/// use algotrees::binary_trees::{initialize, prelude::BinaryTree};
///
/// let tree: BinaryTree<i32> = initialize::create_empty();
///
/// assert_eq!(
/// tree,
/// BinaryTree {
/// head: 0,
/// left: None,
/// right: None
/// }
/// )
/// ```