mercredi 2 décembre 2015

Setting a current node pointer to either a right or left node in a binary tree

I have looked through quite extensively (and hopefully haven't missed it) but I cannot seem to find any help in my current predicament. So here is the problem:

I am attempting to change my current node in a binary tree to either the right or left child depending on what the user wants to do, I have several other functions in the program I.E. (move up, move down-right, move down-left) and then you can cout the current item. The issue is that I can change the item to the right child but not the left one, it is as if the left child does not exist... Here is the code snippet of what I am attempting to do:

`else if (choice == 3)
        {
            if (Ptr->left != NULL)
            {
                system("CLS");
                current = Ptr->left;
                std::cout << "Moved to the left item..." << std::endl;
                system("PAUSE");
            }

            else
            {
                system("CLS");
                std::cout << "Cannot move left any further..." << std::endl;
                system("PAUSE");
            }
        }`

The same technique is applied to the right-side as well. I am quite new to trees and perhaps an "array" style tree would be better than my current dynamic tree, I am using a recursive function that is dynamically re-sized as needed by the user. Hopefully I included all the relevant information. If I need to put anything else in I would happily do so to get some help! Many thanks for the help!

Aucun commentaire:

Enregistrer un commentaire