CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    May 2009
    Posts
    13

    Exclamation problems in my binary tree header program

    Hello to everyone,

    I'm getting some boring errors in my program.. I need a quick help from u all..

    Thanx in advance..

    ----------------------------------------------------------------------------------------

    #include <iostream.h>

    using namespace std;

    template <class T>
    struct node{
    T info;
    node<T> *llink, *rlink;
    };

    template <class T>
    class BinaryTree{
    protected:
    node<T> *root;
    private:
    void destroy(node<T> *&);
    void preordert(node<T> *);
    void inordert(node<T> *);
    void postordert(node<T> *);
    int high(node<T> *);
    int max(int,int);
    public:
    BinaryTree(){root=NULL;}
    ~BinaryTree(){destroy(root);}
    bool isEmpty(){return root==NULL;}
    void preorder(){preordert(root);}
    void inorder(){inordert(root);}
    void postorder(){postorder(root);}
    };
    template <class T>
    void BinaryTree<T>::inordert(node<T> *p)
    { if(p!=NULL)
    {inordert(p->llink);
    cout<<p->info;
    inordert(p->rlink);
    }
    }
    template <class T>
    void BinaryTree<T>:reordert(node<T> *p)
    { if(p!=NULL)
    {cout<<p->info;
    preordert(p->llink);
    preordert(p->rlink);
    }
    }
    template <class T>
    void BinaryTree<T>:ostorder(node<T> *p)
    { if(p!=NULL)
    {postorder(p->llink);
    postorder(p->rlink);
    cout<<p->info;
    }
    }

    template <class T>
    class BSearchTree::BinaryTree<T> // derived from BinaryTree
    {
    public:
    node<T> search(T&);
    void insert(T&);
    void deletenode(T&);
    void deletenode(T&);
    private:
    void deletefromnode(node<T> &);
    };
    template <class T>
    node<T> BSearchTree<T>::search(T &item)
    {node<T> *p;
    bool found=false;
    if(root==NULL)
    return NULL;
    else
    {p=root;
    while(p!=NULL && !found)
    { if(p->info==item)
    found=true;
    else if (p->info->item)
    p=p->link;
    }
    if(found) return p;
    else return NULL;
    }
    }

    --------------------------------------------------------

    p.s. : Errors are attached..
    Attached Images Attached Images  

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured