Skip to content

Instantly share code, notes, and snippets.

@comtom
Created December 3, 2014 15:15
Show Gist options
  • Select an option

  • Save comtom/8a32ac6c9af584f25495 to your computer and use it in GitHub Desktop.

Select an option

Save comtom/8a32ac6c9af584f25495 to your computer and use it in GitHub Desktop.
//Ejercicio 2P2014-E02B;
// Dado un árbol n-ario de caracteres, determinar mediante
// una función si algún nodo formaba con sus hijos
// exactamente la palabra C A S A (en ese orden).
function busCasa(p:posicion; A:tArbol):boolean;
var
c: posicion;
casa: string;
begin
casa:= 'CASA';
if nulo(p) then begin
// caso no recursivo
busCASA:= false;
end
else begin
c:= hijo_mas_izq(p, A);
// comprobacion casa
i:= 1;
cumple:= true;
while cumple and (i<=5) do begin
if i<5 then begin
if casa[i]=info(c, A) then
i:= i+1
else
cumple:= false;
end
else begin //es casa
if nulo(c)=nil then
i:= i+1 //si cumple salgo del while
else
cumple:= false;
end
//avanzar
c:= hno_der(c,A);
end
if cumple and (i=6) then
busCasa:= true
else
// recursividad, verifico cond. en hijos
c:= hijo_mas_izq(p, a);
while not nulo(c) then begin
auxBool:= auxBool or busCasa(c, A);
c:= hno_der(c, A);
end
busCasa:= auxBool;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment