Use the #format when uploading code and give some hints about how your program works if you post a lot of code.
I'm not sure about this, because i'm not familiar with null-pointers, but i think that thats your problem. The following code gives the same run-time error:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
usingnamespace std;
int main()
{
int * pointer;
pointer=NULL;
*pointer=5;
cout<<pointer;
cin.ignore();
return 0;
}
You call the function treefun::inorder() without parameters. That function calls treefun::inorder(treeNode * node) with as parameter root, wich is on this moment a NULL-pointer. In the function treefun::inorder(treeNode * node) you use this parameter several times, wich causes problems. That was my point in my code above: using NULL-pointers gives problems.
I am sure about this: the problem is in these lines (i'm sure, because if you delete them, the program runs without problems):
1 2 3
inorder (node->left); // L
inorder (node->right); // R
Null pointer
A null pointer is a regular pointer of any pointer type which has a special value that indicates that it is not pointing to any valid reference or memory address. This value is the result of type-casting the integer value zero to any pointer type.
int * p;
p = 0; // p has a null pointer value
Do not confuse null pointers with void pointers. A null pointer is a value that any pointer may take to represent that it is pointing to "nowhere", while a void pointer is a special type of pointer that can point to somewhere without a specific type. One refers to the value stored in the pointer itself and the other to the type of data it points to.
You can understand that you cant store a value into "nowhere". You first need to give the pointer an addres: type* pointer=&variable