I have updated the code. I can get it to build a tree, yet the lnr (in order traversal) doesn't work. I've looked at several tutorials - even copy/pasted someone else's inorder traversal code and just changed the keywords around to fit mine and still it didn't work.
/*****************************search***************************
* Used to search for a keyname. *
**************************************************************/
}
else if(strcmp(keyname,p->prez) > 0)
{
p = p->right;
}
else if(strcmp(keyname,p->prez) == 0)
{
found = true;
cout << keyname << " is already in the list!" << endl;
}
}
where = p;
whereprev = pprev;
}
/***************************insertNode****************************
* Used to insert a node into the tree *
*****************************************************************/
/**************************lnr function****************************
* Traverses the tree by going left branch, node, right branch *
******************************************************************/
i'm a little tired, but just glancing at your code, I believe that in line 72: while(p != NULL && strcmp(keyname,p->prez) != 0),
even though a NULL root will invalidate the first condition, i'm pretty sure strcmp() still gets called, and if so, you are trying to access a data member of a structure that doesn't exist. also, it looks like your search function is non-recursive, meaning it will not be able to find anything that is not in the first node. notice that probably your biggest problem is that in your insertNode() function, you make a new node, set all of it's data... then never assign it anywhere. then when that function exits, you lose the pointer to it, and have no way to access that memory anymore! then in main, right after that, you print out that it has been inserted without ever checking if it really was. you also don't need the '&' in front of 'root' in the definition of your insertNode() function because you are not actually calling that function there. hope that helped
thank you firedraco. so just to clarify, as i am interested, when using && or ||, and multiple expressions, they are evaluated left to right? so whichever you put first will be evaluated first?
EX: A && B || C != A && (B || C) because && has a higher precedence then ||.
I'm pretty sure most of them short circuit, i.e. and returns false is left it false, or returns true if left is true, etc. Although if you overload them, they will NOT short circuit the same way, which can cause problems...
@nmcentire: I may be wrong, but I think:
fin.getline(keyname, 80); will read a line of "fin" until it reaches character 80 or the end of the file...you should leave the parameter blank (it defaults to the newline character for you)