Creer l'arbre morse a partir d'un tableau

iroka -  
 iroka -
Bonjour,
voici un code que j'ai préparé pour creer l'arbre morse a partir d'un tableau constant

#include<stdio.h>
#include<stdlib.h>

typedef struct noeud
{
char val;
struct noeud*FG,*FD;
}*arbre;

typedef struct tab
{
char c;
char morse[4];
int large;
};

struct tab t[] =
{
{'a',".-",2}
,{'b',"-...",4}
,{'c',"-.-.",4}
,{'d',"-..",3}
,{'e',".",1}
,{'f',"..-.",4}
,{'g',"--.",3}
,{'h',"....",4}
,{'i',"..",2}
,{'j',".---",4}
,{'k',"-.-",3}
,{'l',".-..",4}
,{'m',"--",2}
,{'n',"-.",2}
,{'o',"---",3}
,{'p',".--.",4}
,{'q',"--.-",4}
,{'r',".-.",3}
,{'s',"...",3}
,{'t',"-",1}
,{'u',"..-",3}
,{'v',"...-",4}
,{'w',".--",3}
,{'x',"-..-",4}
,{'y',"-.--",4}
,{'z',"--..",4}
,};

//****************************************************************************************************
//creation de l'arbre morse

void consnoeud (arbre FG,char val,arbre FD)
{
arbre r;
r=arbre malloc(sizeof(struct noeud));
r->val=val;
r->FG=FG;
r->FD=FD;
return(r);
}
//insere un neoud dans l'arbre
arbre inserer(tab t[],int i,arbre r);
{

if (t[i].morse == '\0')
{
if (t == NULL)
return cons_cell(NULL,t[i].c,NULL);
else {
r->val =t[i].c;
return (r);
}
}
if (r== NULL)
r= cons_cell(NULL,'\0',NULL);
if (t[i].morse== '.')
r->FG = inserer(t[i].c,i+1,r->FD);
if(t[i].morse== '-')
r->FD= inserer(t[i].c,i+1,r->FD);
return r;
}
void prefix(arbre r)
{
if (r!=NULL)
{
printf("%c",r->val);
prefix(r->FG);
prefix(r->FD);

}
}
main()
{
arbre n=NULL;
for(i=0;i<26;i++)
n=inserer(tab t[],int i,arbre n);
prefix(arbre n);
}

vous pouvez me dire svp quelle est l'erreur dans ce code
et esque vous avez des document sur le codage et decodage morse utulisant les B arbre
merci de ton aide
Configuration: Windows Vista
Firefox 3.5.7

2 réponses

  1. BadGuitarist Messages postés 373 Statut Membre 27
     
    Bonsoir Iroka,

    Et cela ressemble à quoi l'arbre morse ?

    @+
    0
  2. iroka
     
    bjr BadGuitarist
    le but et d'utuliser les arbre binarire de recherche pour coder et decoder les textes morse
    la creation de cette arbre doit etre a partir d'un tableau constant

    #include<stdio.h>
    #include<stdlib.h>

    typedef struct noeud
    {
    char val;
    struct noeud*FG,*FD;
    }*arbre;

    typedef struct tab
    {
    char c;
    char morse[4];
    int large;
    };

    struct tab t[] =
    {
    {'a',".-",2}
    ,{'b',"-...",4}
    ,{'c',"-.-.",4}
    ,{'d',"-..",3}
    ,{'e',".",1}
    ,{'f',"..-.",4}
    ,{'g',"--.",3}
    ,{'h',"....",4}
    ,{'i',"..",2}
    ,{'j',".---",4}
    ,{'k',"-.-",3}
    ,{'l',".-..",4}
    ,{'m',"--",2}
    ,{'n',"-.",2}
    ,{'o',"---",3}
    ,{'p',".--.",4}
    ,{'q',"--.-",4}
    ,{'r',".-.",3}
    ,{'s',"...",3}
    ,{'t',"-",1}
    ,{'u',"..-",3}
    ,{'v',"...-",4}
    ,{'w',".--",3}
    ,{'x',"-..-",4}
    ,{'y',"-.--",4}
    ,{'z',"--..",4}
    ,};

    //****************************************************************************************************
    //creation de l'arbre morse

    arbre consnoeud (arbre FG,char val,arbre FD)
    {
    arbre r;
    r=arbre malloc(sizeof(struct noeud));
    r->val=val;
    r->FG=FG;
    r->FD=FD;
    return(r);
    }
    //insere un neoud dans l'arbre
    arbre inserer(tab t[].c,tab t[].morse[],int i,int j ,arbre r);
    {

    if (t[i].morse[j] == '\0')
    {
    if (t == NULL)
    return cons_cell(NULL,t[i].c,NULL);
    else {
    r->val =t[i].c;
    return (r);
    }
    }
    if (r== NULL)
    r= consneud(NULL,'\0',NULL);
    if (t[i].morse[j]== '.')
    r->FG = inserer(t[i].c,t[i].morse[j],i+1,j+1,r->FG);
    if(t[i].morse[j]== '-')
    r->FD= inserer(t[i].c,t[i].morse[j],i+1,j+1,r->FD);
    return r;
    }
    void prefix(arbre r)
    {
    if (r!=NULL)
    {
    printf("%c",r->val);
    prefix(r->FG);
    prefix(r->FD);

    }
    }
    main()
    {
    arbre n=NULL;
    for(i=0;i<26;i++)
    for(j=1;j<5;j++)
    n=inserer(t[].c,t[].morse[], i,j, n);
    prefix(arbre n);
    }
    0