Simple breadth first question

I've got a working Binary Tree class, and a working breadth first traversal (using stl queue), but just need someone to help me implement a level feature.
for example, a tree with root 'a' and two children 'b' and 'c' on my program outputs a b c, where i would like it to output
a
b c

Heres my code for breadthfirst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void Tree::breadthfirst(Tree *t) {

	queue<Tree> q;

	q.push(*t);
	while (!q.empty()) {

		*t=q.front();

		q.pop();

		cout << t->RootData() << " ";

		if (t->Left() != NULL)

			q.push(*t->Left());

		if (t->Right() != NULL)

			q.push(*t->Right());

	}


}
Last edited on
please don't double-post. http://www.cplusplus.com/forum/beginner/21121/

Ciao, Imi.
Topic archived. No new replies allowed.