# incluir ltstdio.h gt
# incluir ltstring.h gt
#Definir MAXSIZE 127
bool fun(char *Pre , char *Indor, char *Seq, int n, int R)
{
int i, root
if (n lt= 0) p>
Devuelve 1;
for(root = 0; (root ltn) amp; amp(Indor[root]!= Pre[0]); root );
if(root gt; = n)
return 0;
seq[R]= Pre[0];
for(I = 0; i ltr; i )
if(secuencia[i] == 0)
seq[I]="0";
bool b1 = divertido(Pre 1, Indor, Seq, raíz, 2 * R 1);
bool b2 = fun(Pre 1 raíz, Indor raíz 1, Seq, n - raíz - 1, 2 * R 2 ); p> p>
Regresar b 1 ampB2;
}
int main(void)
{
char; Pre[ 20], Indor[20], Seq[MAXSIZE], n, I;
bool bCreatOk
Printf("Ingrese la secuencia inicial: \ n ");
scanf("s ", Pre);
Printf("Ingrese la secuencia intermedia: \ n ");
scanf("s ", Indor
p>n = strlen(Pre);
for(I = 0; IltMAXSIZEi)
seq[I]= 0;
bCreatOk = fun(Pre, Indor, Seq, n, 0);
If (b creado) {
Printf("¡El árbol binario se construyó correctamente! Su El árbol binario de secuencia es:\n" );
for(I = 0; secuencia [I]; i )
printf("3c ", Seq[I]);
}
Else printf("¡No es un árbol binario válido! ");
printf(" \ n ");
}
Ejecutar resultados