summaryrefslogtreecommitdiff
path: root/branches/hugues/glagen/algo_distribue/tree/main.cc
blob: 3b6f02dd3294923ccd2da78f1b7797c5ea1e8be5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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);
}