From 695965a636bddfbafa0e8b8c66bfd3e7efa5d440 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c> Date: Thu, 10 Feb 2005 23:10:52 +0000 Subject: 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 --- tags/START/glagen/algo_distribue/tree/Makefile | 45 ++++++++++++ tags/START/glagen/algo_distribue/tree/main.cc | 99 ++++++++++++++++++++++++++ tags/START/glagen/algo_distribue/tree/node.cc | 11 +++ tags/START/glagen/algo_distribue/tree/node.hh | 78 ++++++++++++++++++++ tags/START/glagen/algo_distribue/tree/tree.cc | 11 +++ tags/START/glagen/algo_distribue/tree/tree.hh | 51 +++++++++++++ 6 files changed, 295 insertions(+) create mode 100644 tags/START/glagen/algo_distribue/tree/Makefile create mode 100644 tags/START/glagen/algo_distribue/tree/main.cc create mode 100644 tags/START/glagen/algo_distribue/tree/node.cc create mode 100644 tags/START/glagen/algo_distribue/tree/node.hh create mode 100644 tags/START/glagen/algo_distribue/tree/tree.cc create mode 100644 tags/START/glagen/algo_distribue/tree/tree.hh (limited to 'tags/START/glagen/algo_distribue/tree') diff --git a/tags/START/glagen/algo_distribue/tree/Makefile b/tags/START/glagen/algo_distribue/tree/Makefile new file mode 100644 index 0000000..895117b --- /dev/null +++ b/tags/START/glagen/algo_distribue/tree/Makefile @@ -0,0 +1,45 @@ +## +## Makefile for in +## +## Made by meng-tih lam +## Login +## +## Started on Thu Feb 7 19:08:57 2002 meng-tih lam + +## + +NAME = glagen_tree +SRCS = node.cc tree.cc main.cc + +OBJS = $(SRCS:.cc=.o) + +ARCHI_i586 = -g2 -Wall -W -Werror -O3 +ARCHI_NetBSD = -g2 -Wall -W -Werror -O3 -I/usr/X11R6/include +ARCHI_sun4 = -g2 -Wall -W -Werror -O3 +ARCHI_alpha = -g2 -Wall -W -Werror -O3 + +LIB_i586 = +LIB_NetBSD = -L/usr/pkg/lib -L/usr/X11R6/lib -lGL -lGLU -lglut +LIB_alpha = +LIB_sun4 = + +CPPFLAGS = -I. +CC = g++ +RM = rm -f + +.PHONY: all clean deps + +all: $(OBJS) + $(CC) -o $(NAME) $(CFLAGS) $(OBJS)\ + $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE}) + +.cc.o: + $(CC) $(ARCHI_${HOSTTYPE}) $(CPPFLAGS) -c $< + +clean: + $(RM) $(OBJS) $(NAME) *~ \#*\# + +deps: + makedepend $(SRC) 2>/dev/null + +re: clean all diff --git a/tags/START/glagen/algo_distribue/tree/main.cc b/tags/START/glagen/algo_distribue/tree/main.cc new file mode 100644 index 0000000..3b6f02d --- /dev/null +++ b/tags/START/glagen/algo_distribue/tree/main.cc @@ -0,0 +1,99 @@ +// +// main.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:41:45 2002 meng-tih lam +// + +#include +#include +#include + +#include "node.hh" +#include "tree.hh" + +// Pour construire un arbre, il faut d'abord faire les fils +// et les raccoller avec le pere avec la methode add_tree + +int test_tree() +{ + // ** Exemple avec la classe ** + // ** On peut mettre n'importe classe ** + + // * Support du sous-arbre * + string root = "Connection..."; + string a = "Est-ce que ca fonctionne ?"; + string b = "1212123"; + string c = "OK recu 5/5"; + Tree tree(root); + tree.add_node(a); + tree.add_node(b); + tree.add_node(c); + + // Affichage root de l'arbre + std::cout << "root: " << tree.get_node_root().get_data() << std::endl; + + // Affichage de ses fils + unsigned int nb_childs = tree.get_nb_childs(); + for (unsigned int i = 0; i < nb_childs; ++i) + std::cout << tree.get_child(i).get_data() << std::endl; + std::cout << std::endl << std::endl; + + + + // * Support Arbre principale * + Tree main_tree("Execution..."); + + // Voici la methode pour lier un arbre et un sous-arbre + main_tree.add_tree(tree); + + std::cout << "root main: " << main_tree.get_node_root().get_data() + << std::endl; + unsigned int nb_childs2 = main_tree.get_nb_childs(); + + // Ici arbre sur 2 niveaux (Bien sur qu'on peut faire en recursivite ^_^) + for (unsigned int i = 0; i < nb_childs2; ++i) + { + nb_childs = main_tree.get_child(i).get_nb_childs(); + std::cout << main_tree.get_child(i).get_data() << std::endl; + for (unsigned int j = 0; j < nb_childs; ++j) + std::cout << main_tree.get_child(i).get_child(j).get_data() + << std::endl; + } + std::cout << std::endl << std::endl; + + + + + // * Allez on rajoute pour compliquer les choses * + Tree tree2("Une tentative de suicide"); + tree2.add_node("Ou ca?"); + tree2.add_node("A Epita"); + tree2.add_node("Ping pong ping"); + main_tree.add_tree(tree2); + + std::cout << "root main: " << main_tree.get_node_root().get_data() + << std::endl; + nb_childs2 = main_tree.get_nb_childs(); + + // Ici arbre sur 2 niveaux (Bien sur qu'on peut faire en recursivite ^_^) + for (unsigned int i = 0; i < nb_childs2; ++i) + { + nb_childs = main_tree.get_child(i).get_nb_childs(); + std::cout << main_tree.get_child(i).get_data() << std::endl; + for (unsigned int j = 0; j < nb_childs; ++j) + std::cout << main_tree.get_child(i).get_child(j).get_data() + << std::endl; + } + + return (0); +} + + +int main() +{ + test_tree(); + return (0); +} diff --git a/tags/START/glagen/algo_distribue/tree/node.cc b/tags/START/glagen/algo_distribue/tree/node.cc new file mode 100644 index 0000000..a3ae387 --- /dev/null +++ b/tags/START/glagen/algo_distribue/tree/node.cc @@ -0,0 +1,11 @@ +// +// node.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:40:40 2002 meng-tih lam +// Last update Fri Aug 16 02:41:05 2002 meng-tih lam +// + +#include "node.hh" 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 +// Rajouter l'include correspondant a la template de TYPENODE +// + implemente le std::cout abtrait pour les tests + +template class Tree; // Declaration prealable + +template class Node +{ + friend class Tree; + +public: + Node(const TYPENODE &d) : _link(new std::list), _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* get_childs() const { return (_link); } + + unsigned int get_number_node() const + { + unsigned int number_childs = _link->size(); + std::list::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::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 ptr_node = *new std::list; + ptr_node.push_back(*this); + while (ptr_node.size()) + { + std::list::iterator childs = ptr_node.begin(); + std::list::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 *_link; // Pointeur vers le sous-arbre + TYPENODE _data; +}; + +#endif // NODE_HH_ diff --git a/tags/START/glagen/algo_distribue/tree/tree.cc b/tags/START/glagen/algo_distribue/tree/tree.cc new file mode 100644 index 0000000..047ca89 --- /dev/null +++ b/tags/START/glagen/algo_distribue/tree/tree.cc @@ -0,0 +1,11 @@ +// +// tree.cc for in +// +// Made by meng-tih lam +// Login +// +// Started on Fri Aug 16 02:45:56 2002 meng-tih lam +// Last update Fri Aug 16 17:11:24 2002 meng-tih lam +// + +#include "tree.hh" diff --git a/tags/START/glagen/algo_distribue/tree/tree.hh b/tags/START/glagen/algo_distribue/tree/tree.hh new file mode 100644 index 0000000..86ce136 --- /dev/null +++ b/tags/START/glagen/algo_distribue/tree/tree.hh @@ -0,0 +1,51 @@ + + +#ifndef TREE_HH_ +# define TREE_HH_ + +#include +#include +#include "node.hh" +// Rajouter l'include correspondant a la template de TYPENODE +// + implemente le std::cout abstrait pour les tests + +template class Tree +{ +public: + // Construit la racine de l'arbre avec l'info dans son contenu + Tree(const TYPENODE& value) : _root(new Node(value)) {} + + Tree(const Tree& value) : _root(value._root) {} + + // Ajoute un noeud fils (avec info) a l'arbre + void add_node(const TYPENODE& value) { _root->add_child(value); } + + // Renvoie la racine de l'arbre de type Node + Node& get_node_root() const { return (*_root); } + + // Ajoute un autre arbre a la racine de l'arbre courant + void add_tree(const Tree &value) + { + _root->add_tree_node(value.get_node_root()); + } + + // Renvoie la liste de Node de ses fils + std::list< Node >& get_childs() { return _root->get_childs(); } + + // Information du nombre de fils + const unsigned int get_nb_childs() const + { + return (_root->get_nb_childs()); + } + + // Renvoie le noeud fils suivant le numero a partir de 0 + Node get_child(const unsigned int& i) const + { + return (_root->get_child(i)); + } + +private: + Node *_root; +}; + +#endif // TREE_HH_ -- cgit v1.2.3