I am having a few compiling errors due to the syntax confusion on some the functions, Im confused to what im doing wrong, I know its a simple solution I've just been looking at this for hours and cant figure it out.

//Header File
#ifndef BST_H 
#define BST_H
#include <iostream>

namespace cop4530
{

    template <typename T>    
    class BST
    {
    public:

        BST(int th=default_threshold_value);//Constructor
        BST(const string, int th=default_threshold_value);
        BST(const BST&);
        ~BST();
        void buildFromInputString(const string input);
        const BST & operator= (const BST &);
        bool empty();
        void printInOrder() const;
        void printLevelOrder() const;
        int numOfNodes() const;
        int height() const;
        void makeEmpty();
        void insert(const T& v);
        void remove(const T& v);
        bool contains(const T& v);

    private:
        struct BSTNode
        {
            T node;
            BSTNode *leftchild;
            BSTNode *rightchild;
        };
        BSTNode *root;
        void printInOrder(BSTNode *t) const;
        void printLevelOrder(BSTNode *t) const;
        void makeEmpty(BSTNode* &t);
        void insert(const T& v, BSTNode *&t);
        void remove(const T& v, BSTNode *&t);
        bool contains(const T& v, BSTNode *&t);
        int numOfNodes(BSTNode *t) const;
        int height(BSTNode *t) const;
        BSTNode * clone(BSTNode *t) const;
    };
#include "bst.hpp"
}
#endif 

//Implementation File
#include "bst.h"
#include <iostream>
#include <algorithm>
using namespace std;
using namespace cop4530;

template <typename T>
BST <T>::BST(int th=default_threshold_value)
{}

template <typename T>
BST <T>::BST(const string input,int th=default_threshold_value)
{}

template<typename T>
const BST<T> & BST<T>::operator=(const BST & rhs)
{
    if (this !=&rhs)
    {
        makeEmpty();
        root = clone(rhs.root);

    }
    return *this;
}

template <typename T>
BST <T>::BST(const BST&)
{}

template <typename T>
BST <T>::~BST()
{
    makeEmpty();
}


template<typename T>
void BST <T>::buildFromInputString(const string input)
{}

template<typename T>
void BST <T>::printInOrder()const
{}

template<typename T>
void BST <T>::printLevelOrder()const
{}

template<typename T>
void BST <T>::insert(const T& v)
{
    insert(v,root);
}



template<typename T>
void BST <T>::remove(const T& v)
{
    remove(v, root);
}

template<typename T>
void BST <T>::makeEmpty()
{
    makeEmpty();
}

template<typename T>
void BST <T>::makeEmpty(BSTNode* &t)
{
    if (t != NULL)
    {
        makeEmpty(t->leftchild);
        makeEmpty(t->rightchild);
        delete t;
    }
    t = NULL;
}

template<typename T>
int BST <T>::height() const
{}

template<typename T>
int BST <T>::numOfNodes() const
{}


template<typename T>
bool BST <T>::contains(const T& v)
{
    return contains(v,root);
}

template<typename T>
bool BST <T>::empty()
{}

template<typename T>
void BST <T>::printInOrder(BSTNode *t) const
{}

template<typename T>
void BST <T>::printLevelOrder(BSTNode *t) const
{}

template<typename T>
void BST <T>::insert(const T& v, BSTNode *&t)
{
    if (t == NULL)
    {
        t = new BSTNode(v, NULL, NULL); 
    }
    else if (v < t->node)
    {
        insert(v, t->leftchild);
    }
    else if (t->node < v)
    {
        insert(v, t->rightchild);
    }
    else;

}

template<typename T>
void BST <T>::remove(const T& v, BSTNode *&t)
{
    if (t == NULL)
    {
        return;
    }
    if (v < t->node) 
    {
        remove(v, t->leftchild);
    }
    else if (t->node < v)
    {
        remove(v,t->rightchild);
    }
    else if (t->leftchild != NULL && t->rightchild != NULL)
    {
        //
    }
    else 
    {
        BSTNode *oldNode = t;
        t = (t->leftchild != NULL) ? t->leftchild : t->rightchild;
        delete oldNode;
    }

}

template<typename T>
bool BST <T>::contains(const T& v, BSTNode *&t)
{
    if (t == NULL)
    {
        return false;
    }
    else if (v < t->node)
    {
        return contain(v, t->leftchild);
    }
    else if (t->node < v)
    {
        return contain(v, t->rightchild);
    }
    else {
        return true;
    }
}

BST <T>::BSTNode * clone(BSTNode *t) const
{
    if (t == NULL)
    {
        return NULL;
    }
    return new BSTNode(t->node, clone(t-leftchild), clone(t->rightchild));

}

template<typename T>
int BST <T>::numOfNodes(BSTNode *t) const
{}

template<typename T>
int BST <T>::height(BSTNode *t) const
{}

Recommended Answers

All 2 Replies

Please post the compliation errors if you want quick help.

As per Agni - post compiler errors or what your problem is. Just posting 250 lines of code (more or less) is not usefull. Sure we could analyze it in detail - I'm paid $50USD+ per hour to do that just for my normal employment, and $200USD for consulting time (as a senior IEEE member). So, some explanation of your problems would be helpful, and encourage me to respond in kind... :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.