I could really use some help here :(

Started by
3 comments, last by TheGecko 22 years, 4 months ago
Hey people, I've got a nasty little problem here that I can't seem to figure out.I've written an application in MFC to display a BTree with all it's children.The problem I'm having is actually drawing the damn thing properly. For example,I'm trying to draw a tree of order 2.Which means that each root node can have a maximum of 5 children and a minimum of 0 children.So each node can have any number of children from 0 to 5.This complicates things a little bit. Anyway,I need to write a recursive DrawTree() algorithm that goes through all the children in the tree starting with the root node and draw all the nodes CENTERED.That's my problem. Consider this data structure:
          
#define MAX_KEYSINNODE  4
#define MAX_CHILDREN  5

#define NODE_WIDTH  115 //Width of the node in pixels


#define NODE_HEIGHT 20  //Height of the node in pixels


typedef struct BTreeNode
{
	int		Count;
	int		Keys[MAX_KEYSINNODE];

	BTreeNode	*Children[MAX_CHILDREN];

}BTreeNode;

BTreeNode *root;
          
And I need to write a function DrawTree(BTreeNode *t,int x,int y) Of course,the parameters need more work.But I really need some help here.Any one have any ideas? Thanx in advance. For those of you who wanna see what I'm talking about,check out this screenshot of my application at work btree.jpg This screenshot was hardcoded to draw the tree properly I know,I'm ashamed.So sue me! Edited by - TheGecko on December 6, 2001 8:17:33 PM [edit: link] Edited by - Magmai Kai Holmlor on December 6, 2001 11:29:56 PM
Advertisement
Oh,by the way,Count is an integer that stores how many keys we have in the node.And it is an integer between 0 and 4

the magic of recursion

oops i also forgot to mention be more specific with your question like pstiong yoru drawing code and the trouble you are having with it

Edited by - a person on December 6, 2001 11:25:55 PM
Is a tree control out-of-the-question? or do you have to draw it on the screen all-pretty like?

The solution to this problem is part of geometry, though the name of the theorem eludes me.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
If there is a BTree activeX control,then by all means,show me where I can download it! But,in a sense,yes I have to draw it all pretty like.Specifically,I have to draw the entire tree centered on the screen.And that''s the problem I''m having.

This topic is closed to new replies.

Advertisement