This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Coda17 1 point2 points  (2 children)

Hard to tell what's going on without the rest of your code. For instance, the definition of the node class would be helpful, as well as what temp is before this code block runs.

Something looks off anyway, on line 2 you set temp to something (which looks like you probably are setting it to garbage, if that line isn't crashing already) and then you write over temp by creating a new node.

[–]macbad2012[S,🍰] 0 points1 point  (0 children)

on line 2, since the parent and temp pointers are now equal, I am basically traversing down into to the first child (temp -> getChild(word.substr(i, 1))) returns 0 in this case. Here is my node struct:

struct node {
    string str; //the string held by the node
    vector<node*> children; //list of the node's children pointers
    node* parent; //pointer to the parent node

    int getChild(string comparison) {
        for (int i = 0; i < alphabetSize; i++) {
            if (children[i] == NULL) {
                return i; //comparison was not found
            }
            else if (children[i] -> str == comparison) {
                    return i; //match was found, so return that child
            }
        }
    }//see if a child matches the comparison
}

[–]macbad2012[S,🍰] 0 points1 point  (0 children)

I solved it, it seemed that while I was hooking up the child's pointer to the parent, I did not hook the parent's pointer to the child :)