Commit 3dc228e3 by Vít Novotný

### rewrote the examples using linked lists

parent 2cee916f
 ... ... @@ -5,21 +5,14 @@ # klici hasove tabulky jsou jmena potomku, hodnotami jmena rodicu otec = dict(dana="milan", petr="milan", david="jan") matka = dict(dana="pavla", petr="pavla", david="jana") potomci = dict() def _init_potomci(): for y in otec: potomci[y] = True for y in matka: potomci[y] = True _init_potomci() potomci = set(otec.keys() + matka.keys()) # pravidla def rodic_testuj(x, y): def rodic(x, y): return y in otec and otec[y] == x or \ y in matka and matka[y] == x def rodic_generuj_Xs(y): def rodic_anyX(y): xs = [] if y in otec: xs.append(otec[y]) ... ... @@ -27,21 +20,21 @@ def rodic_generuj_Xs(y): xs.append(matka[y]) return xs def sourozenci_testuj(x, y): def sourozenci(x, y): return x in otec and y in otec and otec[x] == otec[y] and x != y and \ x in matka and y in matka and matka[x] == matka[y] def sourozenci_generuj_Ys(x): def sourozenci_anyY(x): ys = [] for y in potomci: if sourozenci_testuj(x, y): if sourozenci(x, y): ys.append(y) return ys # demonstracni vypis if __name__ == "__main__": print('Vysledek dotazu otec["dana"] je %s.' % [otec["dana"]]) print('Vysledek dotazu rodic_generuj_Xs("david") je %s.' % \ rodic_generuj_Xs("david")) print('Vysledek dotazu sourozenci_generuj_Ys("dana") je %s.' % \ sourozenci_generuj_Ys("dana")) print("Vysledek dotazu otec['dana'] je '%s'." % otec["dana"]) print("Vysledek dotazu rodic_anyX('david') je %s." % \ rodic_anyX("david")) print("Vysledek dotazu sourozenci_anyY('dana') je %s." % \ sourozenci_anyY("dana"))
 #!/usr/bin/env python # encoding=utf-8 (pep 0263) from linked_lists import LinkedList, Nil def member(x, ys): for y in ys: if x == y: return True return False if ys == Nil: return False if x == ys.head: return True return member(x, ys.tail) # demonstracni vypis if __name__ == "__main__": print("Member - 3. varianta") print('Vysledek volani member("a", ["a", "b", "a"]) je %d.' % \ member("a", ["a", "b", "a"]) and "True" or "False") print("Vysledek volani member('a', LinkedList('a', 'b', 'a')) je %s." % \ member("a", LinkedList("a", "b", "a")))