Hi everyone, i want to ask question about how to make a multiple tree in c++. So i want to make a tree which contain more than 2 child(or node or leaf), but i don't know how to make a tree like this. does anyone have an example about this? i would really thankful if you share how to make the tree.

Thank you so much.

Do you have code to make a tree with 2 leafs per parent? Show us this and indicate where you think it would need to be modified to make more than 2 leafs, and we'll see if you're on the right track.

Dave

Do you have code to make a tree with 2 leafs per parent? Show us this and indicate where you think it would need to be modified to make more than 2 leafs, and we'll see if you're on the right track.

Dave

thank you Dave,

i've tried to make a tree:

struct Node_Tag
{
        short    NodeType;    /* 0=leaf 1=branch 2=cut 3=subset */
        ClassNo   Leaf;        /* most frequent class at this node */
        
	short    Forks;        /* number of branches at this node */
	
	Node_Tag	*Branch;	/* Branch[x] = (sub)tree for outcome x */
	//Node_Tag*	child;
};
typedef struct Node_Tag Node;

i've assigned several value so i can use the tree:

void DiscreteTest(Node *N, Attribute Att)
{
	int va = (int) nilaiVAtribut[Att].size();

	N->Forks = va;
    
	N->Branch = (Node *) calloc(va+1, sizeof(Node));
	
	N -> NodeType = 1;
	N -> Tested = Att;
	N -> Errors = 0;
	printf("node si att: %d\n", Att);
}

and i call to make a branch in this code:

ForEach(v, 0, N -> Forks)
{
	if(Fp <= Kp)
	{
		N->Branch = FormTree(Fp, Kp);
		//N -> Errors += N -> Branch -> Errors;
	}
	else
	{
		N -> Branch = LeafType;
		N->Items=0; 
		N->Errors=0;
	};
}

when i ran it, it gave me an error message:

193 [main] c45 324 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
11373 [main] c45 324 open_stackdumpfile: Dumping stack trace to c45.exe.stackdump

and when i tried to change how to call the branch, thus:

N->Branch[B][v][/B] = FormTree(Fp, Kp);

it gave another error message:

c45.cpp: In function `Node* FormTree(ItemNo, ItemNo)':
c45.cpp:659: error: no match for 'operator=' in '*(N->Node_Tag::Branch + (+(((unsigned int)v) * 40u))) = FormTree(Fp, Kp)'
tree.h:13: note: candidates are: Node_Tag& Node_Tag::operator=(const Node_Tag&)

i stuck with this problem for 4 days, i really don't know where the mistakes are..i'm depressed..really need help here :(

thank you :)

This article has been dead for over six months. Start a new discussion instead.