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);

Recommended Answers

All 2 Replies

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 ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.