Binary search tree getting depth of each node

Im trying to traverse a binary search tree and get the depth of each node and sum them up. Im using a file which has 7 numbers "nodes"

4
6
7
5
2
3
1

the code doesn't output numbers 5 and 3 because the pointers never point to them and causes a core dump(here's my problem), how can successful traverse my tree in order to get the depth of each node?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

unsigned get_cost_sum_of_nodes (node_type * p_node)
{
		
 int lf_counter = 0;
 int rt_counter =1;
 node_type* rp = m_root;
		
		
	if(p_node&&rp == NULL)
	{
	 return lf_counter+ rt_counter;	
	}
		
	while (p_node!=NULL)
	{
	 lf_counter++;
	 rt_counter++;
		  
 std::cout<<"Key: "<<p_node->get_key()<<" Search cost: "<<lf_counter<<std::endl;
 rp = rp->get_right_child();
 std::cout<<"Key: "<<rp->get_key()<<" Search cost: "<<rt_counter<<std::endl;
 p_node = p_node->get_left_child();
		  
    } 
			
		 
			
 }	
Topic archived. No new replies allowed.