Arbre Binaire - Constructeur De Copie

Je suis en train de créer un constructeur de copie pour mon arbre Binaire.

Mon problème:

Je peux voir les valeurs de la source de l'arbre de prise en copié dans l'arborescence cible, mais quand il vient à l'écriture des valeurs, il n'y a pas de valeurs dans la copie d'un arbre et il crash de mon programme.

Message D'Erreur:

Exception non gérée à 0x0097a43c dans binTree.exe: 0xC0000005: violation d'Accès lecture de l'emplacement 0xccccccec.

Code:

//Méthode Principale

    int main(int argc, char **) {
    ifstream fin6("input_data.txt");
    ofstream out9("copied_tree.txt");

    if(!fin6.is_open()) 
    {
        cout << "FAIL" << endl;
        return 1;
    }

    BinaryTreeStorage binaryTreeStorage2;

    //read in values into data structure
    binaryTreeStorage2.read(fin6);

    BinaryTreeStorage binaryTreeStorage3 = binaryTreeStorage2;

    //output values in data structure to a file
    binaryTreeStorage3.write(out9);

    fin6.close();
    out9.close();

    //pause
    cout << endl << "Finished" << endl;
    int keypress; cin >> keypress;
    return 0;
}

//Constructeur De Copie

BinaryTreeStorage::BinaryTreeStorage(BinaryTreeStorage &source)
{
    if(source.root == NULL)
        root = NULL;
    else
        copyTree(this->root, source.root);
}

//Copie La Méthode D'Arbre

void BinaryTreeStorage::copyTree(node *thisRoot, node *sourceRoot)
{
    if(sourceRoot == NULL)
    {
        thisRoot = NULL;
    }
    else
    {
        thisRoot = new node;
        thisRoot->nodeValue = sourceRoot->nodeValue;
        copyTree(thisRoot->left, sourceRoot->left);
        copyTree(thisRoot->right, sourceRoot->right);
    }
}
InformationsquelleAutor MitchellT | 2012-05-02