#ifndef BT_NODE_H #define BT_NODE_H struct btNode {    int data;    btNode* left;    btNode* right; }; // 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 // 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 void portToArrayInOrder(btNode* bst_root, int* portArray); void portToArrayInOrderAux(btNode* bst_root, int* portArray, int& portIndex); // 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) // post: 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.) void bst_insert(btNode* &bst_root, int insInt); // pre:  bst_root is root pointer of a binary search tree (may be 0 for //       empty tree) // post: 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. bool bst_remove(btNode* &bst_root, int insInt); // pre:  bst_root is root pointer of a non-empty binary search tree // post: 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. void bst_remove_max(btNode* &bst_root, int &data); // pre: // post: creates a node filled with the input data and right/left paths set to 0 btNode* create_node(int data); #endif

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

#ifndef BT_NODE_H
#define BT_NODE_H

struct btNode
{
   int data;
   btNode* left;
   btNode* right;
};

// 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
// 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
void portToArrayInOrder(btNode* bst_root, int* portArray);
void portToArrayInOrderAux(btNode* bst_root, int* portArray, int& portIndex);

// 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)
// post: 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.)

void bst_insert(btNode* &bst_root, int insInt);

// pre:  bst_root is root pointer of a binary search tree (may be 0 for
//       empty tree)
// post: 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.

bool bst_remove(btNode* &bst_root, int insInt);

// pre:  bst_root is root pointer of a non-empty binary search tree
// post: 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.

void bst_remove_max(btNode* &bst_root, int &data);

// pre:
// post: creates a node filled with the input data and right/left paths set to 0

btNode* create_node(int data);


#endif

123456789112345678928122342526272829812345拓初粥羽DH2B456784958123456刃898
10
20
30
40
50
60
#include "btNode.h"
void bst_insert (btNode* &bst_root, int insInt) {
if (bst_root == 0) bst_root = create_node (insInt);
btNode* ref = bst_root;
btNode* pRef = bst_root;
while (ref != 0) {
if (ref->data > insInt) {
if (ref->left != 0) {
pRef = ref;
ref= ref->left;
}
}
else {
ref-> left = create_node (insInt);
return;
else if (ref->data < insInt) {
if (ref->right != 0) {
pRef = ref;
ref = ref->right;
}
else {
ref-> right = create_node (ins Int);
return;
}
else {
btNode* create_node(int data) {
btNode* newNode = new btNode;
newNode->data = data;
newNode->left = newNode->right = 0;
return newNode;
ref->data = insInt;
return;
bool bst_remove (btNode* &bst_root, int data) {
}
if (bst_root == 0) return false;
if (bst_root->data > data) return bst_remove (bst_root->left, data);
if (bst_root->data < data) return bst_remove (bst_root->right, data);
(bst_root->data == data) {
if
if (bst_root->right == 0 || bst_root->left == : 0) {
btNode* old_bst_root = bst_root;
if (bst_root->right == 0) bst_root = bst_root->left;
else bst_root = bst_root->right;
delete old_bst_root;
return true;
else {
bst_remove_max(bst_root->left, bst_root->data);
return true;
}
return false;
Transcribed Image Text:123456789112345678928122342526272829812345拓初粥羽DH2B456784958123456刃898 10 20 30 40 50 60 #include "btNode.h" void bst_insert (btNode* &bst_root, int insInt) { if (bst_root == 0) bst_root = create_node (insInt); btNode* ref = bst_root; btNode* pRef = bst_root; while (ref != 0) { if (ref->data > insInt) { if (ref->left != 0) { pRef = ref; ref= ref->left; } } else { ref-> left = create_node (insInt); return; else if (ref->data < insInt) { if (ref->right != 0) { pRef = ref; ref = ref->right; } else { ref-> right = create_node (ins Int); return; } else { btNode* create_node(int data) { btNode* newNode = new btNode; newNode->data = data; newNode->left = newNode->right = 0; return newNode; ref->data = insInt; return; bool bst_remove (btNode* &bst_root, int data) { } if (bst_root == 0) return false; if (bst_root->data > data) return bst_remove (bst_root->left, data); if (bst_root->data < data) return bst_remove (bst_root->right, data); (bst_root->data == data) { if if (bst_root->right == 0 || bst_root->left == : 0) { btNode* old_bst_root = bst_root; if (bst_root->right == 0) bst_root = bst_root->left; else bst_root = bst_root->right; delete old_bst_root; return true; else { bst_remove_max(bst_root->left, bst_root->data); return true; } return false;
4
14
24
C:\Users\reshm\OneDrive\Documents\btNo...
34 C:\Users\reshm\OneDrive\Documents\btNode.cpp
26 C:\Users\reshm\OneDrive\Documents\btNode.cpp
27 C:\Users\reshm\OneDrive\Documents\btNode.cpp
In function 'void bst_insert(btNode* &, int)':
[Error] 'create_node' was not declared in this scope
[Error] 'create_node' was not declared in this scope
[Error] 'create_node' was not declared in this scope
Transcribed Image Text:4 14 24 C:\Users\reshm\OneDrive\Documents\btNo... 34 C:\Users\reshm\OneDrive\Documents\btNode.cpp 26 C:\Users\reshm\OneDrive\Documents\btNode.cpp 27 C:\Users\reshm\OneDrive\Documents\btNode.cpp In function 'void bst_insert(btNode* &, int)': [Error] 'create_node' was not declared in this scope [Error] 'create_node' was not declared in this scope [Error] 'create_node' was not declared in this scope
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY