Advertisement Jump to content
Sign in to follow this  

Binary tree creation

This topic is 4897 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
	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

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

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

	static int i = 0;

	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++;
	tree tree1;
	node node1;
	int i = timeGetTime();

	int ii = timeGetTime();
	//std::cout<<(ii - i)<<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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!