@@ -11,7 +11,7 @@ class Node<num> {
1111class BinarySearchTree {
1212 Node <num >? root;
1313
14- /// Pseudocode:
14+ /// Pseudocode (Iteratively or Recursively) :
1515 /// - Create a new node.
1616 /// - Check if there is a root, if not - the root now becomes that new node.
1717 /// - If there is a root, check if the value of the new node is greater than or less than the value of the root.
@@ -54,7 +54,7 @@ class BinarySearchTree {
5454 return insertHelper (currentRoot);
5555 }
5656
57- /// Pseudocode:
57+ /// Pseudocode (Iteratively or Recursively) :
5858 /// - Starting at the root.
5959 /// - Check if there is a root, if not - we're done searching.
6060 /// - If there is a root, check if the value of the new node is the value we are looking for:
@@ -81,41 +81,41 @@ class BinarySearchTree {
8181void main () {
8282 group ('insert' , () {
8383 test ('should insert items to the correct branches' , () {
84- final bst = BinarySearchTree ();
85- bst .insert (3 );
86- bst .insert (2 );
87- bst .insert (1 );
88- bst .insert (4 );
84+ final tree = BinarySearchTree ();
85+ tree .insert (3 );
86+ tree .insert (2 );
87+ tree .insert (1 );
88+ tree .insert (4 );
8989
90- expect (bst .root, isA <Node >().having ((p) => p.value, 'value' , 3 ));
91- expect (bst .root? .right, isA <Node >().having ((p) => p.value, 'value' , 4 ));
92- expect (bst .root? .left, isA <Node >().having ((p) => p.value, 'value' , 2 ));
93- expect (
94- bst.root ? .left ? .left, isA <Node >().having ((p) => p.value, 'value' , 1 ));
90+ expect (tree .root, isA <Node >().having ((p) => p.value, 'value' , 3 ));
91+ expect (tree .root? .right, isA <Node >().having ((p) => p.value, 'value' , 4 ));
92+ expect (tree .root? .left, isA <Node >().having ((p) => p.value, 'value' , 2 ));
93+ expect (tree.root ? .left ? .left,
94+ isA <Node >().having ((p) => p.value, 'value' , 1 ));
9595 });
9696
9797 test ('should not insert item if it is already there' , () {
98- final bst = BinarySearchTree ();
99- bst .insert (1 );
100- bst .insert (1 );
98+ final tree = BinarySearchTree ();
99+ tree .insert (1 );
100+ tree .insert (1 );
101101
102- expect (bst .root, isA <Node >().having ((p) => p.value, 'value' , 1 ));
103- expect (bst .root? .right, null );
104- expect (bst .root? .left, null );
102+ expect (tree .root, isA <Node >().having ((p) => p.value, 'value' , 1 ));
103+ expect (tree .root? .right, null );
104+ expect (tree .root? .left, null );
105105 });
106106 });
107107
108108 group ('find' , () {
109109 test ('should return true if item is found and false if not found' , () {
110- final bst = BinarySearchTree ();
111- bst .insert (3 );
112- bst .insert (2 );
113- bst .insert (4 );
110+ final tree = BinarySearchTree ();
111+ tree .insert (3 );
112+ tree .insert (2 );
113+ tree .insert (4 );
114114
115- expect (bst .find (3 ), true );
116- expect (bst .find (2 ), true );
117- expect (bst .find (4 ), true );
118- expect (bst .find (1 ), false );
115+ expect (tree .find (3 ), true );
116+ expect (tree .find (2 ), true );
117+ expect (tree .find (4 ), true );
118+ expect (tree .find (1 ), false );
119119 });
120120 });
121121}
0 commit comments