Commit 9cf06b18f107b6b5d14e7b159f5848210667aa1c

Authored by mertz
1 parent f7d9ccda

debut_add_tree

Showing 2 changed files with 66 additions and 10 deletions   Show diff stats
1 -#include "trees.h" 1 +#include "tree.h"
2 2
3 /* 3 /*
4 typedef struct node { 4 typedef struct node {
5 int val; 5 int val;
  6 + int fin;
6 struct node* fils[]; 7 struct node* fils[];
  8 + int nbr_fils;
7 }Node, *PtNode, *Tree; 9 }Node, *PtNode, *Tree;
  10 +
  11 +#include <stdio.h>
  12 +#include <stdlib.h>
  13 +
  14 +int main(){
  15 + int tmp;
  16 + tmp = getchar();
  17 + printf("%d\n",tmp);
  18 + return 0;
  19 +}
  20 +
8 */ 21 */
9 22
10 -void cons_tree(struct node **, int, struct node *) 23 +void cons_tree(struct node ** ptr_tree, int val)
11 { 24 {
  25 + *ptr_tree = malloc(sizeof(struct node));
  26 + (*ptr_tree)->val = val;
  27 + (*ptr_tree)->fin = 0;
  28 + (*ptr_tree)->nbr_fils=0;
  29 + (*ptr_tree)->fils = malloc(sizeof(struct node*));
  30 + (*ptr_tree)->fils[0]=NULL;
12 31
  32 + //(*ptr_tree)->fils = realloc(sizeof(struct node*)*nbr_fils);
  33 + //(*ptr_tree)->fils[nbr_fils];
13 } 34 }
14 35
15 -void mk_empty_tree(struct node **); 36 +void mk_empty_tree(struct node **ptr_tree)
  37 +{
  38 + *ptr_tree = NULL;
  39 +}
16 40
17 -int is_leaf(struct node *); 41 +int is_leaf(struct node *tree)
  42 +{
  43 + return tree->fin||tree->fils[0]==NULL;
  44 +}
18 45
19 -void add(struct node **, int); 46 +void add(struct node ***tab_ptr_tree, int val[],int taille, int fl)
  47 +{
  48 + for(int i=0;i<taille;i++)
  49 + {
  50 + if(*(tab_ptr_tree[fl])==NULL){cons_tree(tab_ptr_tree[fl],val[i]);continue;}
  51 + int trouve = 0;
  52 + for(int j=0;j<(*(tab_ptr_tree[fl]))->nbr_fils;j++)
  53 + {
  54 + if((*(tab_ptr_tree[fl]))->val==val[i])
  55 + {
  56 + trouve=1;
  57 + break;
  58 + }
  59 + }
  60 + if(trouve == 0)
  61 + {
  62 + //ajouter fils
  63 + }
  64 + }
  65 + //mettre fin à 1 pour le bon
  66 + //if(i==taille-1)(*(tab_ptr_tree[fl]))->fin=1; //
  67 +}
20 68
21 -void load_tree(FILE *, struct node **); 69 +void load_tree(FILE *fp, struct node **ptr_tree)
  70 +{
  71 + //fl (first letter)
  72 +}
22 73
23 -void free_tree(struct node **); 74 +void free_tree(struct node **ptr_tree)
  75 +{
  76 +
  77 +}
@@ -3,16 +3,18 @@ @@ -3,16 +3,18 @@
3 3
4 typedef struct node { 4 typedef struct node {
5 int val; 5 int val;
6 - struct node* fils[]; 6 + int fin;
  7 + int nbr_fils;
  8 + struct node** fils;
7 }Node, *PtNode, *Tree; 9 }Node, *PtNode, *Tree;
8 10
9 -void cons_tree(struct node **, int, struct node *); 11 +void cons_tree(struct node **, int);
10 12
11 void mk_empty_tree(struct node **); 13 void mk_empty_tree(struct node **);
12 14
13 int is_leaf(struct node *); 15 int is_leaf(struct node *);
14 16
15 -void add(struct node **, int); 17 +void add(struct node ***, int* ,int ,int);
16 18
17 void load_tree(FILE *, struct node **); 19 void load_tree(FILE *, struct node **);
18 20