I am working with traversals for the first time and am running into some errors with my them I am just going to post my preorder code because I am gettin the same error for post and in order.
The Error:
BSTree.h: In member function âvoid BSTree<T>::printPreorder() const [with T = int]â:
assign6.cpp:30: instantiated from here
BSTree.h:198: error: passing âconst BSTree<int>â as âthisâ argument of âvoid BSTree<T>::pre_trav(TNode<T>*) [with T = int]â discards qualifiers
BSTree.h: In member function âvoid BSTree<T>::printInorder() const [with T = int]â:
template <class T>
void BSTree<T>::printPreorder() const
{
if (root != NULL)
pre_trav(root);
}
template <class T>
void BSTree<T>::pre_trav(TNode<T>* ptr)
{
cout << ptr->data << " ";
if(ptr->left != NULL)
pre_trav(ptr->left);
if(ptr->right != NULL)
pre_trav(ptr->right);
}