HI everyone and Mike, thks for the push. I've managed to come out a little parent, child and sibling relationship loop. Now, i would need to display this replationship into a dynamic the tree structure display. I wonder how can i go about doing it. I have read up the MSDN help, but still couldn't quite makeup the link.
Second, i need node2 as a capture storage,it holds pervious value and compare to the next metadata coming in at a later time.
I wonder did i do it correctly or there is a better way.
Like if first set of data in (parent = Earth, child = USA), Second set of data in (parent = Earth, child = AUS), Both will have the same parent, and USA and AUS are sibling to each other. I need to display this relationship in a tree structure.
Pls advise,
Part of my code is as the followings.
if (node == NULL)
{
if (parentlabel!= NULL)
{
root->label = new char[strlen(parentlabel)+1];
strcpy(root->label,parentlabel);
root->tree = true;
if (childlabel!= NULL)
{
node2 = root->child =new browsernode;;
node2->parent = root;
node2->label = new char[strlen(childlabel)+1];
strcpy(node2->label,childlabel);
node2->tree = true;
}
}
}
else
{
if (parentlabel!= NULL && node->parent != NULL)
{
oldlabel = new char[strlen(node->parent->label)+1];
strcpy(oldlabel,node->parent->label);
for (n =0 ;n < strlen(oldlabel); n++)
{
if(oldlabel[n] != parentlabel[n])
break;
}
if (oldlabel[n] == parentlabel[n] && childlabel != NULL)
{
node2 = new browsernode;
node2->parent = node->parent;
node2->label = new char[strlen(childlabel)+1];
strcpy(node2->label,childlabel);
node->next_sibling = node2;
node2->prev_sibling = node;
}
else
{
root->label = new char[strlen (parentlabel)+1];
strcpy(root->label,parentlabel);
if (childlabel != NULL)
{
node2 = root->child = new browsernode;
node2->parent = root;
node2->label = new char[strlen(childlabel)+1];
strcpy(node2->label, childlabel);
}
}
}
else
if (childlabel != NULL)
{
node = new browsernode;
node = oldnode->parent;
while (node->parent !=NULL)
{
node = node->parent;
}
root = node;
node2 = root->child = new browsernode;
node2->parent = root;
node2->label = new char[strlen(childlabel)+1];
strcpy(node2->label, childlabel);
}
}
return node2;
KIM
|