SimpleMinded
Vault Fossil
sigh, I didn't want to show you guys how super bad i am but I've tried everything and now am in such a despate spot that I've come here. And considering about 95% of the people here are/were comp sci majors or program anyway I thought this would be the best place to ask my question. So in my high school, I took Comp Sci, got a 5 on the AP exam and thus, placed out of the intro level courses of computer science. The only issue was, my course was in java, whereas everything we do at school is in c++.
However, thinking myself magnificent, I figured it didn't matter, read a book on c++ over the summer and entered the higher level courses when I got here. Now I'm realizing I don't know ANY c++. So here's my issue. We're writing a program that's just a Binary Search Tree designed to sort object Contacts. So basically, a binary search tree for the phone book.
So in my header file, I declared a struct treeNode that looks like so:
struct treeNode{
Contact *c;
treeNode *left;
treeNode *right;
};
Now I also declared a treeNode root that would represent the top of the tree. I created a method insert which takes a Contact's information, and adds him to the tree. Now the first time insert is called, it adds the node no problem, then get's the hell out of there. But then, the second time, stuff gets ugly (in the displayed code).
First, the program gets into the while loop because the current Node's contact was initialized, last time in insert. It goes into the first if statement, then into the second and should begine the code i have there. Everything there works fine until I mention curNode->c. For some reason, whenever I even put curNode->c, my program terminates. It doesn't matter if I write = NULL or = new Contact, it just kicks. Am i doing something wrong? If so, what? PLEASE, help me. I went to the campus tutor earlier and he said he hadn't programmed in a long time and thus, couldn't help.
Thanks guys, glad i could bother you. If you need more info, say, the entire function or anything, let me know and I'll see what i can do.
while(curNode->c != NULL){
if(*(curNode->c) > contact){
if(curNode->left == NULL){
curNode->left == new treeNode();
curNode = curNode->left;
curNode->c = NULL;
}
else
curNode = curNode->left;
}
}
However, thinking myself magnificent, I figured it didn't matter, read a book on c++ over the summer and entered the higher level courses when I got here. Now I'm realizing I don't know ANY c++. So here's my issue. We're writing a program that's just a Binary Search Tree designed to sort object Contacts. So basically, a binary search tree for the phone book.
So in my header file, I declared a struct treeNode that looks like so:
struct treeNode{
Contact *c;
treeNode *left;
treeNode *right;
};
Now I also declared a treeNode root that would represent the top of the tree. I created a method insert which takes a Contact's information, and adds him to the tree. Now the first time insert is called, it adds the node no problem, then get's the hell out of there. But then, the second time, stuff gets ugly (in the displayed code).
First, the program gets into the while loop because the current Node's contact was initialized, last time in insert. It goes into the first if statement, then into the second and should begine the code i have there. Everything there works fine until I mention curNode->c. For some reason, whenever I even put curNode->c, my program terminates. It doesn't matter if I write = NULL or = new Contact, it just kicks. Am i doing something wrong? If so, what? PLEASE, help me. I went to the campus tutor earlier and he said he hadn't programmed in a long time and thus, couldn't help.
Thanks guys, glad i could bother you. If you need more info, say, the entire function or anything, let me know and I'll see what i can do.
while(curNode->c != NULL){
if(*(curNode->c) > contact){
if(curNode->left == NULL){
curNode->left == new treeNode();
curNode = curNode->left;
curNode->c = NULL;
}
else
curNode = curNode->left;
}
}