summaryrefslogtreecommitdiff
path: root/tags/START/glagen/algo_distribue/tree/node.hh
diff options
context:
space:
mode:
author(no author) <(no author)@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:52 +0000
committer(no author) <(no author)@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c>2005-02-10 23:10:52 +0000
commit695965a636bddfbafa0e8b8c66bfd3e7efa5d440 (patch)
tree92da17b074c1122ebdcd53f4cd5bc6b34151c83c /tags/START/glagen/algo_distribue/tree/node.hh
parent1761afd30c5baeb038b666a6d838309e1040eb60 (diff)
This commit was manufactured by cvs2svn to create tag 'START'.
git-svn-id: file:///usr/local/opt/svn/repos/glagen@6 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c
Diffstat (limited to 'tags/START/glagen/algo_distribue/tree/node.hh')
-rw-r--r--tags/START/glagen/algo_distribue/tree/node.hh78
1 files changed, 78 insertions, 0 deletions
diff --git a/tags/START/glagen/algo_distribue/tree/node.hh b/tags/START/glagen/algo_distribue/tree/node.hh
new file mode 100644
index 0000000..b80a699
--- /dev/null
+++ b/tags/START/glagen/algo_distribue/tree/node.hh
@@ -0,0 +1,78 @@
+
+#ifndef NODE_HH_
+# define NODE_HH_
+
+#include <list>
+// Rajouter l'include correspondant a la template de TYPENODE
+// + implemente le std::cout abtrait pour les tests
+
+template<class TYPENODE> class Tree; // Declaration prealable
+
+template<class TYPENODE> class Node
+{
+ friend class Tree<TYPENODE>;
+
+public:
+ Node(const TYPENODE &d) : _link(new std::list<Node>), _data(d) {}
+
+ void add_child(const TYPENODE& value) { _link->push_back(Node(value)); }
+
+ void add_tree_node(const Node& value) { _link->push_back(value); }
+
+ TYPENODE get_data() const { return (_data); }
+
+ const unsigned int get_nb_childs() const { return (_link->size()); }
+
+ std::list<Node>* get_childs() const { return (_link); }
+
+ unsigned int get_number_node() const
+ {
+ unsigned int number_childs = _link->size();
+ std::list<Node>::const_iterator child = _link->begin();
+ unsigned int number_node = 1;
+ for (unsigned int tmp = 0; tmp != number_childs; ++tmp)
+ {
+ number_node += child->get_number_node();
+ ++child;
+ }
+ return (number_node);
+ }
+
+ // Renvoie le noeud fils suivant le numero a partir de 0
+ Node get_child(const unsigned int& i) const
+ {
+ assert(i < _link->size());
+ std::list<Node>::const_iterator child = _link->begin();
+ for (unsigned int tmp = 0; tmp != i; ++tmp)
+ ++child;
+ return (*child);
+ }
+
+ // Numerotation de l'arbre suivant un parcours en largeur de 0 a n
+ Node get_node_course_width(const int& ptr) const
+ {
+ int rptr = ptr;
+ std::list<Node> ptr_node = *new std::list<Node>;
+ ptr_node.push_back(*this);
+ while (ptr_node.size())
+ {
+ std::list<Node>::iterator childs = ptr_node.begin();
+ std::list<Node>::iterator child = childs->get_childs()->begin();
+ for (; child != childs->get_childs()->end(); ++child)
+ {
+ ptr_node.push_back(*child);
+ if (--rptr == 0)
+ return (*child);
+ }
+ ptr_node.pop_front();
+ }
+ return (*this);
+ }
+
+private:
+
+ std::list<Node> *_link; // Pointeur vers le sous-arbre
+ TYPENODE _data;
+};
+
+#endif // NODE_HH_