tree.c
1.33 KB
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
#include "tree.h"
/*
typedef struct node {
int val;
int fin;
struct node* fils[];
int nbr_fils;
}Node, *PtNode, *Tree;
#include <stdio.h>
#include <stdlib.h>
int main(){
int tmp;
tmp = getchar();
printf("%d\n",tmp);
return 0;
}
*/
void cons_tree(struct node ** ptr_tree, int val)
{
*ptr_tree = malloc(sizeof(struct node));
(*ptr_tree)->val = val;
(*ptr_tree)->fin = 0;
(*ptr_tree)->nbr_fils=0;
(*ptr_tree)->fils = malloc(sizeof(struct node*));
(*ptr_tree)->fils[0]=NULL;
//(*ptr_tree)->fils = realloc(sizeof(struct node*)*nbr_fils);
//(*ptr_tree)->fils[nbr_fils];
}
void mk_empty_tree(struct node **ptr_tree)
{
*ptr_tree = NULL;
}
int is_leaf(struct node *tree)
{
return tree->fin||tree->fils[0]==NULL;
}
void add(struct node ***tab_ptr_tree, int val[],int taille, int fl)
{
for(int i=0;i<taille;i++)
{
if(*(tab_ptr_tree[fl])==NULL){cons_tree(tab_ptr_tree[fl],val[i]);continue;}
int trouve = 0;
for(int j=0;j<(*(tab_ptr_tree[fl]))->nbr_fils;j++)
{
if((*(tab_ptr_tree[fl]))->val==val[i])
{
trouve=1;
break;
}
}
if(trouve == 0)
{
//ajouter fils
}
}
//mettre fin à 1 pour le bon
//if(i==taille-1)(*(tab_ptr_tree[fl]))->fin=1; //
}
void load_tree(FILE *fp, struct node **ptr_tree)
{
//fl (first letter)
}
void free_tree(struct node **ptr_tree)
{
}