moveshhh 0 Newbie Poster

I have a binary tree with find and print functions. Only problem is I have no idea how to copy a binary tree, while overloading the = operator. Any help in the right direction is appreciated.
My code is below. Only for the header file though. Didn't know if the cpp file was necessary to show, as it just makes use of the header file.

#ifndef _myset_h
#define _myset_h
#include <iostream>
#include <string>
using namespace std;

template <class T>
class Node {
public:
	T value;
	Node<T> *left, *right;
	Node() {left=right=NULL;}
	Node(T item) {value=item; right=left=NULL;}
	Node<T>* find(const T &item);
};

template <class T>
class myset {
private:
	Node<T> *root;
public:
	myset() {root = NULL;}
	myset(T item) {root = new Node<T>(item);}

	bool Add(const T &item) {

		if(root != NULL){
			return Add(item, root);
		}
		else {
			root = new Node<T>(item);
			return true;
		}
	}

	bool Add( const T &item, Node<T> *currentnode ){

		if(currentnode->value == item){
			return false;
		}
		else if(currentnode->value > item){
			if(currentnode->left == NULL){
				currentnode->left = new Node<T>(item);
				return true;
			}
			return Add(item, currentnode->left);
		}
		else {
			if(currentnode->right == NULL){
				currentnode->right = new Node<T>(item);
				return true;
			}
			return Add(item, currentnode->right);
		}

	}

	void print() {
		cout << endl;
		if (root != NULL) print(root);
	}

	void print(Node<T> *current){
		if (current->left != NULL) print(current->left);
		cout << current->value << endl;
		if (current->right != NULL) print(current->right);
	}

	Node<T>* find(const T &item){
		if (root == NULL) 
			return NULL;
		else 
			return find(root,item);
	}

	Node<T>* find(Node<T> *current, T item){
		if (current->value == item) {
			return current;
		}
		if (item < current->value) {
			if (current->left != NULL )
				return find(current->left,item);
			else 
				return NULL;
		}
		else {    
			if (current->right != NULL )
				return find(current->right,item);
			else 
				return NULL;
		}
	}

	~myset() {
		if (root != NULL) destroy(root);
	}

	void destroy(Node<T> *current){
		if (current->left != NULL) destroy(current->left);
		if (current->right != NULL) destroy(current->right);
		cout <<"destroying..." << current->value << endl;
		delete current;
	}


	
	myset operator= (const myset<T>& L){

	return copy();

}

	void copy(const myset<T>& oldset){

	}

};
#endif
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.