Question: What does it mean No viable conversion from Node to Node ? I am tryint to build a binary search tree and this is the
What does it mean No viable conversion from Node
I am tryint to build a binary search tree and this is the error I get for the add in the implementation of the BST class function:
Node class:
template <class ItemType>
class Node
{
private:
ItemType item;
Node *right;
Node *left;
public:
Node();
Node(const ItemType& aNum);
void setItem(const ItemType& aNum);
ItemType getItem() const;
bool isLeaf() const;
void setRight(Node* rightPtr);
void setLeft(Node* leftPtr);
Node* getRight() const;
Node* getLeft() const;
};
template <class ItemType>
Node
{
right = nullptr;
left = nullptr;
} //end default constructor
template <class ItemType>
Node
{
} //end 2nd constructor
template <class ItemType>
void Node
{
item = aNum;
}
template <class ItemType>
void Node
{
right = rightNodePtr;
}
template <class ItemType>
void Node
{
left = leftNodePtr;
}
template <class ItemType>
ItemType Node
{
return item;
}
template <class ItemType>
Node
{
return right;
}
template <class ItemType>
Node
{
return right;
}
template <class ItemType>
class BST
{
private:
Node
protected:
int getHeightHelper(Node
Node
void remove(Node
void inorder(void visit(ItemType&), Node
public:
BST();
BST(const ItemType& rootItem);
BST(const ItemType& rootItem,
const Node
const Node
bool isEmpty() const;
int getHeight() const;
bool add(const ItemType& newData);
void remove(const ItemType& data);
void inOrderTraverse(void visit(ItemType&));
void displayInOrder();
void inOrder(Node
};
template <class ItemType>
BST
{
rootPtr = nullptr;
}
template <class ItemType>
BST
{
rootPtr = rootItem;
}
template <class ItemType>
bool BST
{
Node
rootPtr = placeNode(rootPtr, newNodePtr );
return true;
}
template <class ItemType>
Node
{
Node
if(subTreePtr == nullptr)
return newNodePtr;
else if(subTreePtr->getItem() > newNodePtr->getItem())
{
tempPtr = placeNode(subTreePtr->getLeft(), newNodePtr);
subTreePtr->setLeft(tempPtr);
}
else
{
tempPtr = placeNode(subTreePtr->getRight(), newNodePtr);
subTreePtr->setRight(tempPtr);
}
return subTreePtr;
}
int main()
{
BST<int> tree;
for (int i = 1; i<=5; i++)
{
int random = rand() %100;
tree.add(random);
}
tree.displayInOrder();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
