diff options
author | hugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c> | 2006-03-25 15:07:51 +0000 |
---|---|---|
committer | Hugues Hiegel <hugues@hiegel.fr> | 2008-03-18 10:06:55 +0100 |
commit | 56cc59cf44ec64440ba4d1c0d005196195c758e6 (patch) | |
tree | 0e4bc431438a05c2e32b8703a8c79dcbf26a7cbf /algo_distribue/tree/main.cc | |
parent | d49be924baa2759aefa5b5311a35adf50db48e12 (diff) |
git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c
Diffstat (limited to 'algo_distribue/tree/main.cc')
-rw-r--r-- | algo_distribue/tree/main.cc | 99 |
1 files changed, 99 insertions, 0 deletions
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 <lam_m@epita.fr> +// +// Started on Fri Aug 16 02:41:45 2002 meng-tih lam +// + +#include <iostream> +#include <list> +#include <string> + +#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 <string> ** + // ** 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<string> 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<string> 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<string> 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); +} |