Segmentation Fault. Please Help

My program prints out segmentation fault. It sounds like my pointer tries to access invalid address. I point out the part that may cause problem when I run gdb. Please help me analysis why it cause segmentation fault.
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
void BinarySearchTree::print()
{
	vector<Node*> myvector;
	int height = find_height(m_root);
	if(m_root!=NULL)
	{
		myvector.push_back(m_root);
		print_tree_graph(myvector, height, 1);
	}
}
//this part I got problem.
void BinarySearchTree::print_tree_graph(vector<Node*> &node, int height, int level)
{	
	int floor = height-level;
	int edge_line = pow(2, max((floor-1), 0));
	int first_space = pow (2, floor) -1;
	int between_space = pow(2, (floor+1))-1;
	print_space(first_space);
	vector<Node*> myvector;
	for (unsigned int i=0; i<node.size(); i++) 
	{
		if(node.at(i)!=NULL)
		{
			cout<<node.at(i)->m_number;
			myvector.push_back(node.at(i)->m_left);
			myvector.push_back(node.at(i)->m_right);	
		}else{
			myvector.push_back(NULL);
			myvector.push_back(NULL);
			print_space(1);
		}
		print_space(between_space);
	}
	cout<<"myvector: " <<myvector.size()<<endl;
	for(unsigned int i=0; i<myvector.size(); i++)
		cout<<myvector[i]->m_number <<" ";
	cout<<"\n";
	for(int i=1; i<=edge_line; i++)
	{
		for(unsigned int j=0; j< node.size(); j++)
		{
			print_space(first_space-i);
			if(node[j]==NULL)
				print_space(edge_line+edge_line+1);
			if(node[j]->m_left!=NULL)
				cout<<"/";
			else
				print_space(1);
			print_space(i + i -1);
			if(node[j]->m_right!=NULL)
				cout<<"\\";
			else
				print_space(1);
			print_space(edge_line + edge_line -i);
		}
		cout<<"\n";
	}
	level++;
	print_tree_graph(myvector, height, level);
	myvector.clear();
	node.clear();
}


void BinarySearchTree::print_space(int count)
{
	for(int i=0; i<count; i++)
		cout<<" ";
}

int BinarySearchTree::find_height()
{
	return find_height(m_root);
}

int BinarySearchTree::find_height(Node*&  node)
{
	if(node == NULL)
		return 0;
	else
		return max( find_height(node ->m_left) +1, find_height(node->m_right)+1);
}

int BinarySearchTree::max(int a, int b)
{
	return (a >= b ? a : b);
}
which line is the segfault occuring on?
for(unsigned int i=0; i<myvector.size(); i++)
cout<<myvector[i]->m_number <<" ";
it starts line 35 and 36. Once I comment line 36, it passed the program. If I run line 36, it will generate segmentation fault.
Actually, I create a binary search tree structure. I stored each node in a vector.
Once I want to print out the tree, I use vector to access the element by indexing. I think this is the problem that cause segmentation fault. the type of pointer ...
actually, you can see this page. I post my whole program.
http://www.cplusplus.com/forum/beginner/73233/
you can run it. it will pass the compiling but will generate seg fault finally.
Why don't YOU take a look at that link, and maybe you will see that somebody already anwered the question!
Topic archived. No new replies allowed.