Here's what I have so far

template <class KT, class DT>
void my_bst<KT,DT>::show_bst_structure(my_bst_node<KT,DT>*& p) const
	my_bst_node<KT,DT>* le=NULL;
	my_bst_node<KT,DT>* ri=NULL;
	//empty tree
		cout<<"tree is empty\n";
		//print node key
		else if(p->left!=NULL)
			cout<<"enter left\n";
		else if(p->right!=NULL)
			cout<<"enter right\n";

Edited 7 Years Ago by lotrsimp12345: n/a

When printing a binary tree you can either print it in pre, mid, or post
order. I am not going to explain all of these. You should google them.

The usual way one would display a binary tree is by either one of the printing methods from above, pre ,post or min.

The way below is mid order :

void _recursivePrint(_Node* &Parent){					
		if(Parent != _NULL){
			std::cout << Parent->data.var <<" ";
		else return;

A per order would put the cout statement before the parent->leftChild
recursive call and a post order would put it after the recursive call

What it does is it first goes all the way to the left most node. And prints
it. If the left most node has a right node, then it prints that. It "goes"
up the tree like that. Google it, better explanation out there. Its late
so I can't use my brain much.

Edited 7 Years Ago by firstPerson: n/a

i got those functions to work. I need depth-first approach. Is their any way to do this without a stack or queue?

conclusion don't think its possible with just a recursive function since the number of links keep on increasing as you go down the tree :(. Wasted 24 hours on this.

This question has already been answered. Start a new discussion instead.