Hello! It is my first post and I've got probably easy question. I can use containers like list, vector. But I think there is no tree container in standard containers of C++. I found this site and I'd like to use it. The problem is that I do not know how to create trees with this tree.h.
This is my listing:
#include <cstdlib>
#include <iostream>
#include <string>
//source of tree.h:
//http://www.gamedev.net/reference/articles/article2192.asp
#include "tree.h"
using namespace std;
class dir //directory
{
public:
dir() : itsName("katalog") {} //default constructor
explicit dir(const string &name) : itsName(name) {} //constructor
const string &getName() const { return itsName; } //accessor
bool operator==(const dir &rhs) const
{ return this->getName() == rhs.getName(); }
bool operator<(const dir &rhs) const
{ return this->getName() < rhs.getName(); }
private:
string itsName;
};
void temp() //temporary function which creates simple tree of directories
//and shows the result
{
using namespace core; //namespace from tree.h
tree<dir> leafDir; //it creates tree of dir
//glowny -> kata (dira (subdir), dirb), katb (dirc), katc
tree<dir>::iterator iter = leafDir.insert(dir("glowny")); //root of tree
iter = iter.insert(dir("kata"));
//... AND HERE I CAN'T WRITE THE PROPER CODE
}
int main(int argc, char *argv[])
{
temp();
system("PAUSE");
return EXIT_SUCCESS;
}
I'd like to create an examplary tree (so that I can train how to use tree.h):
main
---dir1
------subdir1
---------subdir4
------subdir2
---dir2
------subdir3
---dir3
But I don't know how to create new "levels" of the tree, how to "step back" into lower level, how to create branches/leaves on the same level - please, help me.
Greetings and thanks in advance for your help!