The definition for binary search tree should be the one used in class (which is different from that adopted by the suggested-book authors). ► Class definition: Suggested-book definition: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than the item in n ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than or equal the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ● bst_insert must be iterative (NOT recursive). ● bst_remove and bst_remove_max must use the algorithm described by the suggested book authors, appropriately adapted for the difference in tree definition above In btNode.h: provide prototypes for bst_insert, bst_remove and bst_remove_max. ● In btNode.cpp: provide definition (implementation) for bst_insert, bst_remove and bst_remove_max. Here is what the test output is suppose to look like: ============================== test case 1 of 990000 attempt to remove 5 values below: (sequential order) -2 8 -4 0 1 (value-sort order) -4 -2 0 1 8 from 8 values below: -8 -7 -6 -2 -1 0 1 2 gives (with 3 values successfully removed) -8 -7 -6 -1 2 ============================== test case 2 of 990000 attempt to remove 7 values below: (sequential order) 8 -3 -5 -4 5 6 4 (value-sort order) -5 -4 -3 4 5 6 8 from 6 values below: -8 -5 -4 -3 -2 3 gives (with 3 values successfully removed) -8 -2 3 ============================== test case 3 of 990000 attempt to remove 5 values below: (sequential order) 4 -6 -4 -1 6 (value-sort order) -6 -4 -1 4 6 from 11 values below: -8 -7 -6 -5 -4 -2 -1 0 5 6 7 gives (with 4 values successfully removed) -8 -7 -5 -2 0 5 7 ============================== test case 4 of 990000 attempt to remove 1 values below: (sequential order) 8 (value-sort order) 8 from 12 values below: -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 gives (with 0 values successfully removed) -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 ============================== test case 5 of 990000 attempt to remove 8 values below: (sequential order) 4 -6 4 2 -9 7 -7 5 (value-sort order) -9 -7 -6 2 4 4 5 7 from 9 values below: -8 -5 -4 -2 1 2 3 8 9 gives (with 1 values successfully removed) -8 -5 -4 -2 1 3 8 9 ============================== test case 66000 of 990000 attempt to remove 3 values below: (sequential order) 1 -1 7 (value-sort order) -1 1 7 from 4 values below: -5 -3 0 8 gives (with 0 values successfully removed) -5 -3 0 8 ============================== test case 132000 of 990000 attempt to remove 8 val
The definition for binary search tree should be the one used in class (which is different from that adopted by the suggested-book authors). ► Class definition: Suggested-book definition: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than the item in n ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than or equal the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ● bst_insert must be iterative (NOT recursive). ● bst_remove and bst_remove_max must use the algorithm described by the suggested book authors, appropriately adapted for the difference in tree definition above In btNode.h: provide prototypes for bst_insert, bst_remove and bst_remove_max. ● In btNode.cpp: provide definition (implementation) for bst_insert, bst_remove and bst_remove_max. Here is what the test output is suppose to look like: ============================== test case 1 of 990000 attempt to remove 5 values below: (sequential order) -2 8 -4 0 1 (value-sort order) -4 -2 0 1 8 from 8 values below: -8 -7 -6 -2 -1 0 1 2 gives (with 3 values successfully removed) -8 -7 -6 -1 2 ============================== test case 2 of 990000 attempt to remove 7 values below: (sequential order) 8 -3 -5 -4 5 6 4 (value-sort order) -5 -4 -3 4 5 6 8 from 6 values below: -8 -5 -4 -3 -2 3 gives (with 3 values successfully removed) -8 -2 3 ============================== test case 3 of 990000 attempt to remove 5 values below: (sequential order) 4 -6 -4 -1 6 (value-sort order) -6 -4 -1 4 6 from 11 values below: -8 -7 -6 -5 -4 -2 -1 0 5 6 7 gives (with 4 values successfully removed) -8 -7 -5 -2 0 5 7 ============================== test case 4 of 990000 attempt to remove 1 values below: (sequential order) 8 (value-sort order) 8 from 12 values below: -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 gives (with 0 values successfully removed) -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 ============================== test case 5 of 990000 attempt to remove 8 values below: (sequential order) 4 -6 4 2 -9 7 -7 5 (value-sort order) -9 -7 -6 2 4 4 5 7 from 9 values below: -8 -5 -4 -2 1 2 3 8 9 gives (with 1 values successfully removed) -8 -5 -4 -2 1 3 8 9 ============================== test case 66000 of 990000 attempt to remove 3 values below: (sequential order) 1 -1 7 (value-sort order) -1 1 7 from 4 values below: -5 -3 0 8 gives (with 0 values successfully removed) -5 -3 0 8 ============================== test case 132000 of 990000 attempt to remove 8 val
The definition for binary search tree should be the one used in class (which is different from that adopted by the suggested-book authors). ► Class definition: Suggested-book definition: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items: ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than the item in n ♯ For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than or equal the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ♯ For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n ● bst_insert must be iterative (NOT recursive). ● bst_remove and bst_remove_max must use the algorithm described by the suggested book authors, appropriately adapted for the difference in tree definition above In btNode.h: provide prototypes for bst_insert, bst_remove and bst_remove_max. ● In btNode.cpp: provide definition (implementation) for bst_insert, bst_remove and bst_remove_max. Here is what the test output is suppose to look like: ============================== test case 1 of 990000 attempt to remove 5 values below: (sequential order) -2 8 -4 0 1 (value-sort order) -4 -2 0 1 8 from 8 values below: -8 -7 -6 -2 -1 0 1 2 gives (with 3 values successfully removed) -8 -7 -6 -1 2 ============================== test case 2 of 990000 attempt to remove 7 values below: (sequential order) 8 -3 -5 -4 5 6 4 (value-sort order) -5 -4 -3 4 5 6 8 from 6 values below: -8 -5 -4 -3 -2 3 gives (with 3 values successfully removed) -8 -2 3 ============================== test case 3 of 990000 attempt to remove 5 values below: (sequential order) 4 -6 -4 -1 6 (value-sort order) -6 -4 -1 4 6 from 11 values below: -8 -7 -6 -5 -4 -2 -1 0 5 6 7 gives (with 4 values successfully removed) -8 -7 -5 -2 0 5 7 ============================== test case 4 of 990000 attempt to remove 1 values below: (sequential order) 8 (value-sort order) 8 from 12 values below: -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 gives (with 0 values successfully removed) -9 -8 -7 -6 -4 -3 -1 1 3 4 5 9 ============================== test case 5 of 990000 attempt to remove 8 values below: (sequential order) 4 -6 4 2 -9 7 -7 5 (value-sort order) -9 -7 -6 2 4 4 5 7 from 9 values below: -8 -5 -4 -2 1 2 3 8 9 gives (with 1 values successfully removed) -8 -5 -4 -2 1 3 8 9 ============================== test case 66000 of 990000 attempt to remove 3 values below: (sequential order) 1 -1 7 (value-sort order) -1 1 7 from 4 values below: -5 -3 0 8 gives (with 0 values successfully removed) -5 -3 0 8 ============================== test case 132000 of 990000 attempt to remove 8 val
The definition for binary search tree should be the one used in class (which is different from that adopted by the suggested-book authors).
►
Class definition:
Suggested-book definition:
A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items:
A BST is a binary tree that (if not empty) also follows two storage rules regarding its nodes’ items:
♯
For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than the item in n
♯
For any node n of the tree, every item in n’s left subtree (LST), if not empty, is less than or equal the item in n
♯
For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n
♯
For any node n of the tree, every item in n’s right subtree (RST), if not empty, is greater than the item in n
●
bst_insert must be iterative (NOT recursive).
●
bst_remove and bst_remove_max must use the algorithm described by the suggested book authors, appropriately adapted for the difference in tree definition above
In btNode.h: provide prototypes for bst_insert, bst_remove and bst_remove_max.
●
In btNode.cpp: provide definition (implementation) for bst_insert, bst_remove and bst_remove_max.
Here is what the test output is suppose to look like:
Transcribed Image Text:[*]btNode.h X
12345678981234567898122342525278293812345拓劲89812BU456F8498152够弘556刃8 59 =
10
ddddddd□ENN~~~ ~ ~ NO
20
30
40
च च च
50
#ifndef BT_NODE_H
#define BT_NODE_H
struct btNode
{
};
// pre:
int data;
btNode* left;
btNode* right;
// post: The binary search tree has been traversed in-order and the data
values are written (as they are encountered) to portArray in
increasing positional order starting from the first element
portToArrayInOrder (btNode* bst_root, int* portArray);
portToArrayInOrder
Aux (btNode* bst_root, int* portArray, int& portIndex);
void
void
//
// pre: (none)
// post: dynamic memory of all the nodes of the tree rooted at root has been
freed up (returned back to heap/freestore) and the tree is now empty
(root pointer contains the null address)
void tree_clear (btNode*& root);
// pre: (none)
// post: # of nodes contained in tree rooted at root is returned
int bst_size(btNode* bst_root);
//
// pre:
//
bst_root is root pointer of a binary search tree (may be 0 for
empty tree) and portArray has the base address of an array Large
enough to hold all the data items in the binary search tree
bst_root is root pointer of a binary search tree (may be for
empty tree)
If no node in the binary search tree has data equals insInt, a
node with data insInt has been created and inserted at the proper
Location in the tree to maintain binary search tree property.
If a node with data equals insInt is found, the node's data field
has been overwritten with insInt; no new node has been created.
(Latter case seems odd but it's to mimick update of key-associated
data that exists in more general/real-world situations.)
write prototype for bst_insert here
bst_root is root pointer of a binary search tree (may be for
empty tree)
If remInt was in the tree, then remInt has been removed, bst_root
now points to the root of the new (smaller) binary search tree,
and the function returns true. Otherwise, if remInt was not in the
tree, then the tree is unchanged, and the function returns false.
post:
// pre:
// post:
// write prototype for bst_remove here
// pre:
// post:
60 #endif
bst_root is root pointer of a non-empty binary search tree
The Largest item in the binary search tree has been removed, and
bst_root now points to the root of the new (smaller) binary search
tree. The reference parameter, removed, has been set to a copy of
the removed item.
// write prototype for bst_remove_max here
Process or set of rules that allow for the solving of specific, well-defined computational problems through a specific series of commands. This topic is fundamental in computer science, especially with regard to artificial intelligence, databases, graphics, networking, operating systems, and security.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.