what I am trying to do is store same letter to same node. For example: let say I have person, people is sent to be put into a node. This will create two node. I want to some thing like

P: Person People

Person and People are same note

When I run this on Visual Studio I got

C2440 type cast: cannt convert from IntBinaryTree:treeNode to Char;
C2264 std:: basic_string....

void IntBinaryTree::insert(TreeNode *&nodePtr, TreeNode *&newNode)
    string combineworld;
    stringstream sk;
    string newsk;
    string word = nodePtr->value;
    char key = word.at(1);
    sk << key;
    sk >> newsk;
    cout << "newsk : " << key << endl;

    if (nodePtr == NULL)
            nodePtr = newNode;
    stringstream sk2;
    string newsk2;
    string word2 = newNode->value;

    char key2 = word2.at(1);
    sk << key2;
    sk >> newsk2;
    cout << "newsk2 : " << key << endl;

    if (newsk == newsk2)
        combineworld.append(nodePtr, newNode);

    else if (newNode->value < nodePtr->value)
        insert(nodePtr->left, newNode);     // Search the left branch
    insert(nodePtr->right, newNode);    // Search the right branch

void IntBinaryTree::insertNode(string num)
    TreeNode *newNode;      // Pointer to a new node.

    // Create a new node and store num in it.
    newNode = new TreeNode;
    newNode->value = num;
    newNode->left = newNode->right = NULL;

    // Insert the node.
    insert(root, newNode);
1 Year
Discussion Span
Last Post by bernardo.mclobo

Not sure what you mean by IntBinaryTree when your data are in strings?
A better tree design will be template BinaryTree<int> ? BinaryTree<strings> ?


As far as I understand your code (sorry, still learning C++), the problem is that you use a string, instead of an array of chars, and when you pass it to the tree, you pass it as a string, instead of a char ...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.