Please help fix the following errors in red for the code below. (The .h file is not listed due to maximum character count) Bstree.cpp: using namespace std; #include "Bstree.h" /* Nested Node class definitions */ template template Bstree::Node::Node(T item) {    data = item;    left = nullptr;    right = nullptr; } /* Outer Bstree class definitions */ template Bstree::Bstree() {    root = nullptr;    order = 0; } template Bstree::~Bstree() {    recDestroy(root); } template bool Bstree::empty() const {    return root == nullptr; } template void Bstree::insert(T item) {    Node* tmp;    Node* newnode = new Node(item);    /* If it is the first node in the tree */    if (!root)    {       root = newnode;       order++;       return;    }    /*find where it should go */    tmp = root;    while (true)    {       if (tmp->data == item)       { /* Key already exists. */          tmp->data = item;          delete newnode; /* dont need it */          return;       }       else if (tmp->data > item)       {          if (!(tmp->left))          {/* If the key is less than tmp */             tmp->left = newnode;             order++;             return;          }          else          {/* continue searching for insertion pt. */             tmp = tmp->left;          }       }       else       {          if (!(tmp->right))          {/* If the key is greater than tmp */             tmp->right = newnode;             order++;             return;          }          else          {/* continue searching for insertion point*/             tmp = tmp->right;          }       }    } } template bool Bstree::inTree(T item) const {    Node* tmp;    if (!root)       return false;    /*find where it is */    tmp = root;    while (true)    {       if (tmp->data == item)          return true;       else if (tmp->data > item)       {          if (!(tmp->left))             return false;          else          {/* continue searching */             tmp = tmp->left;          }       }       else       {          if (!(tmp->right))             return false;          else             /* continue searching for insertion pt. */             tmp = tmp->right;       }    } } template bool Bstree::remove(const T& item) {    Node* nodeptr = search(item);    if (nodeptr)    {       remove(nodeptr);       order--;       return true;    }    return false; } template const T& Bstree::retrieve(const T& key) const {    Node* nodeptr;    if (!root)       throw BstreeException("Exception:tree empty on retrieve().");    nodeptr = search(key);    if (!nodeptr)       throw BstreeException("Exception: non-existent key on retrieve().");    return nodeptr->data; } template void Bstree::inorderTraverse(FuncType apply) const {    inorderTraverse(root,apply); } template long Bstree::size() const {    return order; } template bool Bstree::remove(Node* node) { T data; Node replacement; Node parent = findParent(node); if (!parent) return false; if (node->left && node->right) /two children case/ { Node* lchild = node->left; Node* lprnt = node; while(lchild->right) { lprnt = lchild; lchild = lchild->right; } data = node->data; node->data = lchild->data; node = lchild; parent = lprnt; } /* one or zero child case / replacement = node->left; if (!replacement) replacement = node->right; if (parent == nullptr) / root */ { delete node; root = replacement; return true; } if (parent->left == node) parent->left = replacement; else parent->right = replacement; delete node; return true;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help fix the following errors in red for the code below.

(The .h file is not listed due to maximum character count)

Bstree.cpp:
using namespace std;
#include "Bstree.h"
/* Nested Node class definitions */
template <typename U>
template <typename T>
Bstree<U>::Node<T>::Node(T item)
{
   data = item;
   left = nullptr;
   right = nullptr;
}
/* Outer Bstree class definitions */
template <typename T>
Bstree<T>::Bstree()
{
   root = nullptr;
   order = 0;
}
template <typename T>
Bstree<T>::~Bstree()
{
   recDestroy(root);
}
template <typename T>
bool Bstree<T>::empty() const
{
   return root == nullptr;
}
template<typename T>
void Bstree<T>::insert(T item)
{
   Node<T>* tmp;
   Node<T>* newnode = new Node<T>(item);
   /* If it is the first node in the tree */
   if (!root)
   {
      root = newnode;
      order++;
      return;
   }
   /*find where it should go */
   tmp = root;
   while (true)
   {
      if (tmp->data == item)
      { /* Key already exists. */
         tmp->data = item;
         delete newnode; /* dont need it */
         return;
      }
      else if (tmp->data > item)
      {
         if (!(tmp->left))
         {/* If the key is less than tmp */
            tmp->left = newnode;
            order++;
            return;
         }
         else
         {/* continue searching for insertion pt. */
            tmp = tmp->left;
         }
      }
      else
      {
         if (!(tmp->right))
         {/* If the key is greater than tmp */
            tmp->right = newnode;
            order++;
            return;
         }
         else
         {/* continue searching for insertion point*/
            tmp = tmp->right;
         }
      }
   }
}
template<typename T>
bool Bstree<T>::inTree(T item) const
{
   Node<T>* tmp;
   if (!root)
      return false;
   /*find where it is */
   tmp = root;
   while (true)
   {
      if (tmp->data == item)
         return true;
      else if (tmp->data > item)
      {
         if (!(tmp->left))
            return false;
         else
         {/* continue searching */
            tmp = tmp->left;
         }
      }
      else
      {
         if (!(tmp->right))
            return false;
         else
            /* continue searching for insertion pt. */
            tmp = tmp->right;
      }
   }
}
template<typename T>
bool Bstree<T>::remove(const T& item)
{
   Node<T>* nodeptr = search(item);
   if (nodeptr)
   {
      remove(nodeptr);
      order--;
      return true;
   }
   return false;
}
template<typename T>
const T& Bstree<T>::retrieve(const T& key) const
{
   Node<T>* nodeptr;
   if (!root)
      throw BstreeException("Exception:tree empty on retrieve().");
   nodeptr = search(key);
   if (!nodeptr)
      throw BstreeException("Exception: non-existent key on retrieve().");
   return nodeptr->data;
}
template<typename T>
void Bstree<T>::inorderTraverse(FuncType apply) const
{
   inorderTraverse(root,apply);
}
template<typename T>
long Bstree<T>::size() const
{
   return order;
}
template<typename T>
bool Bstree<T>::remove(Node<T>* node)
{
T data;
Node<T> replacement;
Node<T> parent = findParent(node);
if (!parent)
return false;
if (node->left && node->right) /two children case/
{
Node<T>* lchild = node->left;
Node<T>* lprnt = node;
while(lchild->right)
{
lprnt = lchild;
lchild = lchild->right;
}
data = node->data;
node->data = lchild->data;
node = lchild;
parent = lprnt;
}
/* one or zero child case /
replacement = node->left;
if (!replacement)
replacement = node->right;
if (parent == nullptr) / root */
{
delete node;
root = replacement;
return true;
}
if (parent->left == node)
parent->left = replacement;
else
parent->right = replacement;
delete node;
return true;
}

Bstree.cpp:17:1: note: candidate expects 1 argument, provided
In file included from Bstree.cpp:13,
from BstreeParser.cpp:32:
Bstree.h:290:18: note: candidate: 'Bstree >::Node >::Node(const Bstree >::Node >&)'
290 class Bstree<U>::Node
Bstree.h:290:18: note: candidate expects 1 argument, provided
Bstree.h:290:18: note: candidate: 'Bstree >::Node >::Node(Bstree >::Node >&&)'
Bstree.h:290:18: note:
candidate expects 1 argument, provided
In file included from BstreeParser.cpp:32:
Bstree.cpp:159:28: error: conversion from 'Bstree >::Node >*' to non-scalar type 'Bstree >::Node >' requested
159 | Node<T> parent = find Parent (node);
Bstree.cpp:160:5: error: no match for 'operator!' (operand type is 'Bstree >::Node >')
160 if (!parent).
Bstree.cpp:160:5: note: candidate: 'operator! (bool)' (built-in)
Bstree.cpp:160:5: note: no known conversion for argument 1 from 'Bstree >::Node >' to 'bool'
Bstree.cpp:183:8: error: cannot convert 'Bstree >::Node >' to 'Bstree >::Node >*' in assignment
183 | root = replacement;
Bstree<std::__cxx11::basic_string<char> >::Node<std::__cxx11:: basic_string<char> >
Bstree.cpp:186:5: error: base operand of '->' has non-pointer type 'Bstree >::Node >'
186 | if (parent->left == node).
Bstree.cpp:187:1: error: base operand of '->' has non-pointer type 'Bstree >::Node >'
187 |_parent->left = replacement;
|^~~~~~
Bstree.cpp:189:1: error: base operand of '->' has non-pointer type 'Bstree >::Node >'
189 |_parent->right = replacement;
Bstree.cpp: In member function 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*)':
Bstree.cpp:162:32: error: expected primary-expression before '/' token
162 | if (node->left && node->right)_/two children case/
Bstree.cpp:162:33: error: 'two' was not declared in this scope
162 | if (node->left && node->right)_/two children case/
Transcribed Image Text:Bstree.cpp:17:1: note: candidate expects 1 argument, provided In file included from Bstree.cpp:13, from BstreeParser.cpp:32: Bstree.h:290:18: note: candidate: 'Bstree >::Node >::Node(const Bstree >::Node >&)' 290 class Bstree<U>::Node Bstree.h:290:18: note: candidate expects 1 argument, provided Bstree.h:290:18: note: candidate: 'Bstree >::Node >::Node(Bstree >::Node >&&)' Bstree.h:290:18: note: candidate expects 1 argument, provided In file included from BstreeParser.cpp:32: Bstree.cpp:159:28: error: conversion from 'Bstree >::Node >*' to non-scalar type 'Bstree >::Node >' requested 159 | Node<T> parent = find Parent (node); Bstree.cpp:160:5: error: no match for 'operator!' (operand type is 'Bstree >::Node >') 160 if (!parent). Bstree.cpp:160:5: note: candidate: 'operator! (bool)' (built-in) Bstree.cpp:160:5: note: no known conversion for argument 1 from 'Bstree >::Node >' to 'bool' Bstree.cpp:183:8: error: cannot convert 'Bstree >::Node >' to 'Bstree >::Node >*' in assignment 183 | root = replacement; Bstree<std::__cxx11::basic_string<char> >::Node<std::__cxx11:: basic_string<char> > Bstree.cpp:186:5: error: base operand of '->' has non-pointer type 'Bstree >::Node >' 186 | if (parent->left == node). Bstree.cpp:187:1: error: base operand of '->' has non-pointer type 'Bstree >::Node >' 187 |_parent->left = replacement; |^~~~~~ Bstree.cpp:189:1: error: base operand of '->' has non-pointer type 'Bstree >::Node >' 189 |_parent->right = replacement; Bstree.cpp: In member function 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*)': Bstree.cpp:162:32: error: expected primary-expression before '/' token 162 | if (node->left && node->right)_/two children case/ Bstree.cpp:162:33: error: 'two' was not declared in this scope 162 | if (node->left && node->right)_/two children case/
Bstree.cpp: In member function 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*)':
Bstree.cpp:162:32: error: expected primary-expression before '/' token
162 | if (node->left && node->right) /two children case/
Bstree.cpp:162:33: error: 'two' was not declared in this scope
162 | if (node->left && node->right) /two children case/
Bstree.cpp: In instantiation of 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*) [with T = std::__cxx11:: basic_string<char>]':
Bstree.cpp:127:13: required from 'bool Bstree:: remove(const T&) [with T = std::__cxx11: :basic_string]'
BstreeParser.cpp:76:25: required from here
Bstree.cpp:158:9: error: no matching function for call to 'Bstree >::Node >::Node()'
158 | Node<T> replacement;
|
Transcribed Image Text:Bstree.cpp: In member function 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*)': Bstree.cpp:162:32: error: expected primary-expression before '/' token 162 | if (node->left && node->right) /two children case/ Bstree.cpp:162:33: error: 'two' was not declared in this scope 162 | if (node->left && node->right) /two children case/ Bstree.cpp: In instantiation of 'bool Bstree<T>:: remove (Bstree<T>::Node<T>*) [with T = std::__cxx11:: basic_string<char>]': Bstree.cpp:127:13: required from 'bool Bstree:: remove(const T&) [with T = std::__cxx11: :basic_string]' BstreeParser.cpp:76:25: required from here Bstree.cpp:158:9: error: no matching function for call to 'Bstree >::Node >::Node()' 158 | Node<T> replacement; |
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education