Skip to main content
gamedev.net
🔒 Locked

Binary tree creation

Started by luasitdown Aug 22, 2005 at 11:17 PM 0 replies 400+ views
Original Post
luasitdown
luasitdown

#include <iostream>
#include <windows.h>
#pragma comment ("winmm.lib")
class node
{
public:
	node():lnode(0),rnode(0),depth(0) {/*std::cout<<"node created!";*/}
	node * lnode;
	node * rnode;
	int    depth;
	int static num;
};
int node::num = 0;

class tree
{
public:

	bool createtree(int lr, node * parent);
private:
	node * root;
};

bool tree::createtree(int lr , node * parent)
{		

	static int i = 0;


 	i++;
		
	parent->depth = i;	
	std::cout<< "node depth:"<<std::endl <<parent->depth<<std::endl;
	if (parent->depth >= )
	return true;


	createtree(1, parent); i--;
	parent->lnode = new node;node::num++;

 	
	createtree(2, parent); i--;
	parent->rnode = new node;node::num++;
	
	
}
main()
{
	tree tree1;
	node node1;
	int i = timeGetTime();
	tree1.createtree(1,&node1);


	int ii = timeGetTime();
	//std::cout<<(ii - i)<<std::endl;
	std::cout<<"num:"<<node::num<<std::endl;
}

I think there are some drawback even error in it. Please give me some opinion. thanks.
snk_kid
snk_kid
What do you intend on using this for? you should look into the standard library containers. In particular look into std::(multi)set/map they are implementated with red-black trees, a binary tree that is overall fairly balanced.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.