0

I am writing a c++ code, it should be able to construct a multitree with the node that I wrote. But I tried to uses the tree containers that I download at the below address to store my node, but all of them seems that cannot store the node which has multiple values in it.

http://www.datasoftsolutions.net/tree_container_library/overview.php

http://archive.gamedev.net/archive/reference/programming/features/coretree2/default.html

struct node{    //construct the node
    char *dirname;
    char date[12];
    int loc;
    bool prot;
}

So are there any tree containers can store the node that I wrote? I need to store the nodes as a multitree.

Xymostech
  • 9,710
  • 3
  • 34
  • 44
CodTango
  • 345
  • 1
  • 3
  • 15
  • 2
    std:map's underlying implementation is a tree; you'll just have to provide a comparison function for comparing two of your 'node' structs. – ryanbwork Nov 28 '12 at 02:05

1 Answers1

0

I doubt that it has anything to do with multiple fields in struct node.

Any data-type stored in a tree is going to require some comparison operators. You will need to figure out which ones the library you are trying to use requires, then implement them for your node type. I took a peek at the documentation. The package is written in C++, uses templates, and is compatible with STL. So it might also require certain typedefs like value_type, etc...

Show us the error messages you are getting and we can work it out. At a minimum, you will probably need to implement operator< and operator!= or equivalents.

UPDATE: In order to search the tree (or to put nodes into it), you will need to define at least operator<. The error message tells us that. You will also probably need operator== to make it work correctly. Try this (untested):

#include <cstring>

bool operator< (const node& left, const node&right) {
    return 0 > strcmp(left.dirname, right.dirname);
}

bool operator== (const node& left, const node&right) {
    return 0 == strcmp(left.dirname, right.dirname);
}
Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
  • The program runs wrong again. "error C2676: binary '<' : 'node' does not define this operator or a conversion to a type acceptable to the predefined operator" Here is one of the error message. So how can I use operators? and it is not necessary to compare two node in my program, I just store them as a multitree and then get them out form the tree by searching the name of the node. – CodTango Nov 28 '12 at 06:40
  • Thanks a lot for your help. I try to add the operators in my struct node and it seems working. But I just did not figure it out, how the operators works, and actually what the left and right comparing? Is it comparing the existing node with the new node that I insert? Then do I need to gives the left and right? and it confusing me, because it looks like binary tree. – CodTango Nov 28 '12 at 14:01
  • Don't put those inside the node structure definition. Put them after. The tree-library code uses those functions to compare the node you specify with nodes already in the tree. – Jive Dadson Nov 28 '12 at 15:07
  • This will be outside the node structure? Then how can I use that? It gives this message:"iterator find(const T &inT, bool (*obj)(const T&, const T&)) const", then how the second parameter should be written? – CodTango Nov 28 '12 at 19:56