Beispiel #1
0
	BST operator = (BST s)
	{
		if (s.root != NULL)
		{
			if (this->root != NULL)
				delete this->root;
			
			this->root = new node;
	
			this->root->key = s.root->key;
	
			if (s.root->LC != NULL)
				this->root->LC = CopyNodes(s.root->LC, this->root);
			else this->root->LC = NULL;

			if (s.root->RC != NULL)
				this->root->RC = CopyNodes(s.root->RC, this->root);
			else this->root->RC = NULL;
		}
		else this->root = NULL;

		this->num = s.num;

		return (*this);
	}
//definition section for CopyNodes
PolyNode* CopyNodes(PolyNode* srcNode)
{
    if (srcNode == nullptr) return nullptr;
    PolyNode* copy = new PolyNode;
    copy->coefficient = srcNode->coefficient;
    copy->power = srcNode->power;
    copy->next = CopyNodes(srcNode->next);
Beispiel #3
0
/*

CopyNodes создает копию листа s как потомка листа parent1. Если у s есть потомки,

то они также копируются к копии как потомки (функция работает рекурсивно)

*/
	node* CopyNodes(node* s, node* parent1)
	{
		node* a = new node;

		a->key = s->key;

		a->parent = parent1;

		if (s->LC != NULL)
			a->LC = CopyNodes(s->LC, a);
		else a->LC = NULL;

		if (s->RC != NULL)
			a->RC = CopyNodes(s->RC, a);
		else a->RC = NULL;

		return a;

	}
Beispiel #4
0
//конструктор копирования
	BST(const BST& s)
	{
		
		if (s.root != NULL)
		{
			root = new node;

			root->key = s.root->key;

			root->parent = NULL;

			if (s.root->LC != NULL)
				this->root->LC = CopyNodes(s.root->LC, root);
			else root->LC = NULL;

			if (s.root->RC != NULL)
				root->RC = CopyNodes(s.root->RC, root);
			else root->RC = NULL;
		}
		else root = NULL;
		this->num = s.num;
		
	}
//definition section for copy constructor
Polynomial::Polynomial(const Polynomial& src)
{