Jump to content
  • Advertisement
Sign in to follow this  
luasitdown

Binary tree creation

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!