fork download
  1. #include <stdio.h>
  2.  
  3. struct Noeud {
  4. int nbr;
  5. Noeud *gauche, *droite;
  6. };
  7.  
  8. static void insertion(Noeud *&top, Noeud *newNoeud) {
  9. if (top == NULL) {
  10. top = newNoeud;
  11. top->droite = NULL;
  12. top->gauche = NULL;
  13. } else if (newNoeud->nbr < top->nbr)
  14. insertion(top->gauche, newNoeud);
  15. else
  16. insertion(top->droite, newNoeud);
  17. }
  18.  
  19. int main() {
  20. Noeud *top = NULL;
  21.  
  22. Noeud *n = new Noeud;
  23. n->nbr = 4;
  24. insertion(top, n);
  25. n = new Noeud;
  26. n->nbr = 10;
  27. insertion(top, n);
  28.  
  29. printf("%d\n", top->nbr);
  30. printf("%d\n", top->droite->nbr);
  31. printf("%p\n", top->gauche);
  32. printf("%p\n", top->droite->gauche);
  33. printf("%p\n", top->droite->droite);
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
4
10
(nil)
(nil)
(nil)