Some weird memory access problem

Hello .. When I return mem add I cannot access the data in that add: in bin search tree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Curr=findMin(root);

cout<<"val: "<<Curr->barcode<<endl;//nothing in printed except val:

bst::hwareItem* bst:: findMin(hwareItem*& root){


    while(root!=NULL){

        root=root->left;
        }

    return root;

}
Last edited on
Your findMin functions does nothing but sets root to null and returns it. So you are trying to dereference null pointer which is illegal.
I changed it to this and it worked

1
2
3
4
5
6
7
8
9
10
11

bst::hwareItem* bst:: findMin(hwareItem*& root){


    while(root->left!=NULL){

        root=root->left;
        }

    return root;
}
Last edited on
Topic archived. No new replies allowed.