Find all nodes in a binary tree on a specific level

Find all nodes in a binary tree on a specific level
I have a BST and I just want to print all nodes on a specific level, ex:
--------123
----82 --125
I want to print all nodes on level 2, ouput is: 82 125
I have code but the output is 82 82, please help me to fix it:
1
2
3
4
5
6
7
8
9
10
11
12
13
 void getLevelQueue(WarriorTree* node, int clevel, int rlevel, Queue& result) 
{

	if (clevel == rlevel)
		result.enqueue(node);
	else
	{
	if (node->pLeftChild != NULL)
		getLevelQueue(node->pLeftChild, clevel + 1, rlevel, result);
	if (node->pRightChild != NULL)
		getLevelQueue(node->pRightChild, clevel + 1, rlevel, result);
	}
}
Last edited on
is your sample output correct? 82 100??
sorry, I've just edited it.
Topic archived. No new replies allowed.