C ++ Homework - Binary Search Tree Help

For starters, this is homework, I just need help with the binary search tree.

The program displays polymorphism using a person as an abstract base class and other types of people who inherit Person. Each person has a last name, and I'm trying to use a binary search tree for the alphabet of people by last name.

I wrote what, in my opinion, should be an acceptable binary search tree, but I'm still getting errors. For the binary search tree, only the insert and move function is required. Which should be recursive.

The error I get is: Error 19 error: C4430: missing type specifier - int is assumed to be bst.cpp

This happens on lines 51, 64 and 70. Here is my code:

Header file:

#ifndef BST_H
#define BST_H

template <class T>
class BST
{
    private:
        class BinNode
        {
            public:
                BinNode(void);
                BinNode(T node);

                BinNode *left;
                BinNode *right;
                T data;
        };

        BinNode* root;

    public:
        BST();   
        ~BST();

        void insert(const T &);
        void traverse();
        void visit(BinNode *);


    //Utlity Functions
    private:
        void insertAux(BinNode* &, BinNode *);
        void traverseAux(BinNode *, ostream &);
};

#include "BST.cpp"
#endif

Implementation File:

 #include <iostream>
#include <string>

using namespace std;

#ifdef BST_H

template <class T>
BST<T>::BinNode::BinNode()
{
    left = right = 0;
}

template <class T>
BST<T>::BinNode::BinNode(T node)
{
   left = right = 0;
   data = node;
}

template <class T>
BST<T>::BST()
{
    root = 0;
}

template <class T>
void BST<T>::insertAux(T i, BinNode* &subRoot)
{
    //inserts into empty tree
    if(subRoot == 0)
        subRoot = new BinNode(i);
    //less then the node
    else if(i<subRoot->data)
        insertAux(i, subRoot->left);
    //greater then node
    else
        insertAux(i, subRoot->right);
}

template <class T>
void BST<T>::insert(const T &i)
{
    insertAux(T i, root)
}

template <class T>
BST<T>::traverse()
{
    traverseAux(root);
}

template <class T>
BST<T>::traverseAux(BinNode *subRoot)
{
    if (subRoot == 0)
        return;
    else
    {
        traverseAux(subRoot->left);
        visit(subRoot);
        traverseAux(subRoot->right);
    }       
}

template <class T>
BST<T>::visit(BinNode *b)
{
    cout << b->data << endl;
}

#endif

- ? . !

+3
2

.

:

template <class T>
BST<T>::traverse()
{
    traverseAux(root);
}

:

template <class T>
void BST<T>::traverse()
{
    traverseAux(root);
}
+3

BST<T>::traverse() void BST<T>::traverse()

erros.

+1

Source: https://habr.com/ru/post/1778641/


All Articles