void BinarySearchTree<T>::copyTree(Node<T> *curNode) {
  if(curNode) {
    insert(curNode->getElement());
    copyTree(curNode->getLeft());
    copyTree(curNode->getRight());
  }
}
예제 #2
0
BinaryNodeTree<ItemType>::BinaryNodeTree(const ItemType& rootItem,
                                         const BinaryNodeTree<ItemType>* leftTreePtr,
                                         const BinaryNodeTree<ItemType>* rightTreePtr)
{
    rootPtr = new BinaryNode<ItemType>(rootItem, copyTree(leftTreePtr->rootPtr), 
                                                 copyTree(rightTreePtr->rootPtr));
}  // end constructor
예제 #3
0
 // create a copy of a binary tree
 TreeNode* copyTree(TreeNode* root) {
     if(root == NULL)
         return NULL;
     TreeNode* p = (TreeNode*)malloc(sizeof(TreeNode));
     p->val = root->val;
     p->left = copyTree(root->left);
     p->right = copyTree(root->right);
     return p;
 }
예제 #4
0
파일: rbtree.c 프로젝트: inste/market
// Walking down the tree and linearize it
void copyTree(Node * a, struct Line * l) {
	if (a == NIL)
		return;

	l->m_items[l->pos].count = a->count;
	l->m_items[l->pos].barCode = a->data;
	++l->pos;
	copyTree(a->left, l);
	copyTree(a->right, l);
}
예제 #5
0
void BSTree::copyTree(Node *treeP,Node *&newP){
    if(treeP != NULL){
        newP = new Node(treeP->customer,NULL,NULL);
        copyTree(treeP->left,newP->left);
        copyTree(treeP->right,newP->right);
    }
    else{
        newP = NULL;//copy empty tree.
    }

}//end copytree
예제 #6
0
KDNode* KDTree::copyTree(KDNode *node) {
    if(node == NULL)
        return NULL;
    KDNode *newNode = new KDNode;
    newNode->objects = node->objects;
    newNode->split_pos = node->split_pos;
    newNode->is_leaf = node->is_leaf;

    newNode->left = copyTree(node->left);
    newNode->right = copyTree(node->right);
    return newNode;
}
예제 #7
0
//----------------------------------------------------------------------------
// copyTree
// Makes an exact copy of the BST using a preorder traversal
void BinTree::copyTree(Node* nodePtr, Node*& newNodePtr) const
{
    if (nodePtr != NULL)
    {
        newNodePtr = new Node; // create new memory for Node
        NodeData* temp = new NodeData(*nodePtr->data); // new memory for data
        newNodePtr->data = temp; // copy data
        copyTree(nodePtr->left, newNodePtr->left);
        copyTree(nodePtr->right, newNodePtr->right);
    }
    else
        newNodePtr = NULL; // copy empty tree
}
예제 #8
0
파일: CTree.hpp 프로젝트: AmosZhu/Template
void CTree<type>::copyTree(TreeNode_t<type>** dst,TreeNode_t<type>* src)
{
    TreeNode_t<type>* newNode;
    if(src==nullptr)
    {
        *dst=nullptr;
        return;
    }
    *dst=new TreeNode_t<type>;
    m_cpyRoute(&(*dst)->elem,&src->elem);
    copyTree(&(*dst)->firstChild,src->firstChild);
    copyTree(&(*dst)->nextSibling,src->nextSibling);
}
예제 #9
0
파일: BST.cpp 프로젝트: elisemmc/EECS268
void BST::copyTree(TreeNode *treePtr, 
                          TreeNode *& newTreePtr) const
{
   // preorder traversal
   if (treePtr != NULL)
   {  // copy node
      newTreePtr = new TreeNode(treePtr->item, NULL, NULL);
      copyTree(treePtr->leftChildPtr, newTreePtr->leftChildPtr);
      copyTree(treePtr->rightChildPtr, newTreePtr->rightChildPtr);
   }  
   else
      newTreePtr = NULL;  // copy empty tree
}  // end copyTree
예제 #10
0
파일: Lex_1.cpp 프로젝트: wangchaohui/lib
struct Node* copyTree(struct Node *x)
{
	if(x==NULL)return NULL;
	struct Node *y=newNode(x->ch,NULL,NULL);
	if(y->ch<256)
	{
		isinput[y->ch]=1;
		y->n=++cc;
		C[y->n]=y->ch;
	}
	y->left=copyTree(x->left);
	y->right=copyTree(x->right);
	return y;
}
예제 #11
0
BinaryNode<ItemType>* BinaryNodeTree<ItemType>::copyTree(const BinaryNode<ItemType>* treePtr) const
{
   BinaryNode<ItemType>* newTreePtr = nullptr;
   
   // Copy tree nodes during a preorder traversal
   if (treePtr != nullptr)
   {
      // Copy node
	   newTreePtr = new BinaryNode<ItemType>(treePtr->getItem(), nullptr, nullptr);
	   newTreePtr->setLeftChildPtr(copyTree(treePtr->getLeftChildPtr()));
      newTreePtr->setRightChildPtr(copyTree(treePtr->getRightChildPtr()));
   }  // end if
   
   return newTreePtr;
}  // end copyTree
예제 #12
0
void binaryTreeType<elemType>::copyTree(nodeType<elemType>* &copiedTreeNode,nodeType<elemType>* otherTreeNode)
{
    if(otherTreeNode==NULL)
    {
        copiedTreeNode=NULL;
        return;
    }


    copiedTreeNode=new nodeType<elemType>;
    copiedTreeNode->info=otherTreeNode->info;
    copyTree(copiedTreeNode->lLink,otherTreeNode->lLink);
    copyTree(copiedTreeNode->rLink,otherTreeNode->rLink);

    return;
}
예제 #13
0
파일: binarytree.c 프로젝트: bobjoris/IPA
BinaryTree* copyTree(BinaryTree * tree){
    BinaryTree* res = malloc(sizeof(BinaryTree));
    
    res->value = tree->value;
    if(leftChild(tree) != NULL)
        res->Left = copyTree(tree->Left);
    else
        res->Left = NULL;
    
    if(rightChild(tree) != NULL)
        res->Right = copyTree(tree->Right);
    else
        res->Right = NULL;
    
    return res;
}
예제 #14
0
void CBinaryTree<type>::copyTree(nodeType<type>** copiedTreeNode,nodeType<type>* otherTreeNode)
{
    if(otherTreeNode==NULL)
    {
        *copiedTreeNode=NULL;
        return;
    }


    *copiedTreeNode=new nodeType<type>;
    memcpy(&(*copiedTreeNode)->elem,&otherTreeNode->elem,sizeof(type));
    copyTree(&(*copiedTreeNode)->lLink,otherTreeNode->lLink);
    copyTree(&(*copiedTreeNode)->rLink,otherTreeNode->rLink);

    return;
}
예제 #15
0
BinaryNode* BinaryTree::copyTree(const BinaryNode* nodePtr)
{
    if (nodePtr == 0)
    {
        return 0;
    }
    
    else
    {
        // make a new node
        BinaryNode* newNode = new BinaryNode(nodePtr->getWebsite());
        newNode->setLeftPtr(copyTree(nodePtr->getLeftPtr()));
        newNode->setRightPtr(copyTree(nodePtr->getRightPtr()));
        return newNode;
    }
}
예제 #16
0
BinaryNodeTree<ItemType>& BinaryNodeTree<ItemType>::operator=(
                                                const BinaryNodeTree<ItemType>& rightHandSide)
{
   if (!isEmpty())
      clear();
   this = copyTree(&rightHandSide);
   return *this;
}  // end operator=
예제 #17
0
파일: BST.cpp 프로젝트: elisemmc/EECS268
BST& BST::operator=(const BST& rhs)
{
   if (this != &rhs)
   {  destroyTree(root);  // deallocate left-hand side
      copyTree(rhs.root, root);  // copy right-hand side
   }  // end if
   return *this;
}  // end operator=
예제 #18
0
KDTree & KDTree::operator=(const KDTree &other) {
    if(this != &other) {
        deleteTree(this->root);
        this->root = copyTree(other.root);
        this->bounds = other.bounds;
    }

    return *this;
}
예제 #19
0
//----------------------------------------------------------------------------
// operator=
// Creates a deep copy of RHS.
BinTree& BinTree::operator=(const BinTree& rhs)
{
    if (this != &rhs)
    {
        destroyTree(root); // destroy LHS
        copyTree(rhs.root, root); // make a deep copy
    }
    return *this;
}
예제 #20
0
binaryTreeType<elemType>::binaryTreeType(const binaryTreeType<elemType>& otherTree)
{
    if(otherTree.root==NULL)
    {
        root=NULL;
        return;
    }

    copyTree(root,otherTree);
}
예제 #21
0
CBinaryTree<type>::CBinaryTree(const CBinaryTree<type>& otherTree)
{
    if(otherTree.m_root==NULL)
    {
        m_root=NULL;
        return;
    }
    m_printRoute=otherTree.m_printRoute;
    copyTree(&m_root,otherTree);
}
예제 #22
0
파일: rbtree.c 프로젝트: inste/market
// Linearizing the tree into array of lCouple structures
struct Line * treeLine(void) {
	struct Line * res = malloc(sizeof(struct Line));

	if (!res)
		err(EMEM);
	res->count = lengthTree(root);
	res->m_items = malloc(res->count * sizeof(struct lCouple));
	res->pos = 0;
	copyTree(root, res);
	return res;
}
예제 #23
0
BinaryTree & BinaryTree::operator= (const BinaryTree & sourceTree)
{
    // clear data first(if the left object is not empty)
    if (!this->isEmpty())
    {
        this->clear();
    }
    rootPtr = copyTree(sourceTree.rootPtr);
    count = sourceTree.count;
    return *this;
}
예제 #24
0
파일: CTree.hpp 프로젝트: AmosZhu/Template
CTree<type>::CTree(const CTree<type>& object)
{
    if(object.IsEmpty())
    {
        m_root=nullptr;
        return;
    }

    copyTree(&m_root,object.m_root);

    return;
}
예제 #25
0
BinaryTree::BinaryTree(const BinaryTree & tree)
{
    // check if the tree is valid
    if (tree.isEmpty())
    {
        rootPtr = 0;
        count = 0;
    }
    else
    {
        // make the pointer pointing to the tree pointer.
        rootPtr = copyTree(tree.rootPtr);
    }
}
예제 #26
0
//return a tree resulted of applying resolution rule
tree resolution(tree t1, tree t2, tree model, int axiom_id) {
    tree result = malloc(sizeof(tree_node));
    int i;
    bool temp = model -> childs[0] -> negative;

    n_resolutions++;

    //change to match if trees are equal
    model -> childs[0] -> negative = !model -> childs[0] -> negative;

    //head of the tree
    strcpy(result -> label, "@");
    result -> n_childs = 0;
    result -> axiom_id = axiom_id + 1;

    //copy to the result tree all the clauses that dont start with the label
    for(i = 0; i < t1 -> n_childs; i++) {
        if(!compareTrees(t1 -> childs[i], model)) {
            result -> childs[result -> n_childs] = copyTree(t1 -> childs[i], NULL);
            result -> childs[result -> n_childs] -> axiom_id = axiom_id + 1;
            result -> n_childs++;
        }
    }

    for(i = 0; i < t2 -> n_childs; i++) {
        if(!compareTrees(t2 -> childs[i], model)) {
            result -> childs[result -> n_childs] = copyTree(t2 -> childs[i], NULL);
            result -> childs[result -> n_childs] -> axiom_id = axiom_id + 1;
            result -> n_childs++;
        }
    }

    model -> childs[0] -> negative = temp;

    return result;
}
예제 #27
0
const binaryTreeType<elemType>& binaryTreeType<elemType>::operator=(const binaryTreeType<elemType>& otherTree)
{
    if(this==otherTree)
        return this;

    if(root!=NULL)
        destroy(root);

    if(otherTree.root==NULL)
    {
        root=NULL;
        return;
    }

    copyTree(root,otherTree);
}
예제 #28
0
파일: CTree.hpp 프로젝트: AmosZhu/Template
const CTree<type>& CTree<type>::operator=(const CTree<type>& object)
{
    if(this==&object)
        return *this;

    destroy(&m_root);

    if(object.IsEmpty())
    {
        m_root=nullptr;
        return *this;
    }

    copyTree(&m_root,object.m_root);

    return *this;
}
예제 #29
0
const CBinaryTree<type>& CBinaryTree<type>::operator=(const CBinaryTree<type>& otherTree)
{
    if(this==otherTree)
        return this;

    if(m_root!=NULL)
        destroy(&m_root);

    if(otherTree.m_root==NULL)
    {
        m_root=NULL;
        return;
    }

    m_printRoute=otherTree.m_printRoute;
    copyTree(m_root,otherTree);
}
BinarySearchTree<T>& BinarySearchTree<T>::operator=(BinarySearchTree& bb) {
  destroyTree();
  Node<T> *curNode = bb.getRoot();
  
  copyTree(curNode);
}