Skip to content
Snippets Groups Projects
Commit 00d6af06 authored by Nikolic's avatar Nikolic
Browse files

Ajout de la function recherche

parent 40a47028
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,11 @@ tree init(){
node * new = NULL;
return new;
}
tree nextLeft(node * node){
return node->left;
}
tree nextRight(node * node){
return node->right;
}
......@@ -29,3 +31,43 @@ void parcours_infix(node * node, int n){
parcours_infix(nextRight(node), n+1);
}
}
int depth(node * node, int nbmax, int nb){
if(node == NULL)
return nb;
int tmp = 0;
tmp = depth(node->left, nbmax, nb++);
if(tmp > nbmax){
nbmax = tmp;
}
tmp = depth(node->right, nbmax, nb++);
if(tmp > nbmax){
nbmax = tmp;
}
return nbmax;
}
char recherche(char * morse, tree tree){
int j = 0;
while (morse[j] != '\0')
{
// Si le caractère est un point on descend à gauche dans l'arbre
if(morse[j] == '.'){
if(tree->left == NULL){
return '\0';
}
tree = tree->left;
}
// Si le caractère est un tiret on desencde à gauche dans l'arbre
else if(morse[j] == '-'){
if(tree->right == NULL){
return '\0';
}
tree = tree->right;
}
j++;
}
return tree->d;
}
\ No newline at end of file
......@@ -35,3 +35,14 @@ void nood_print(node * data);
* Function permettant d'effectuer un parcours d'ordre infixe (GRD)
*/
void parcours_infix(node * node, int n);
/*
* Function permettant de calculer la profondeur de l'arbre
*/
int depth(node * node, int nbmax, int nb);
/*
* Function permettant de trouver à partir d'une séquance morse de quel characère il s'agit
*/
char recherche(char * morse, tree tree);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment