From 56cc59cf44ec64440ba4d1c0d005196195c758e6 Mon Sep 17 00:00:00 2001 From: hugues Date: Sat, 25 Mar 2006 15:07:51 +0000 Subject: Nettoyage du repository glagen git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c --- algo_distribue/tree/main.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 algo_distribue/tree/main.cc (limited to 'algo_distribue/tree/main.cc') diff --git a/algo_distribue/tree/main.cc b/algo_distribue/tree/main.cc new file mode 100644 index 0000000..3b6f02d --- /dev/null +++ b/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); +} -- cgit v1.2.3