public Person(string firstName, string lastName)
public void PrintFamilyTree()
Console.WriteLine(FirstName + " " + LastName);
Mother.PrintFamilyTree();
Father.PrintFamilyTree();
public Person FindParent(string firstName, string lastName)
if (Mother != null && Mother.FirstName == firstName && Mother.LastName == lastName)
if (Father != null && Father.FirstName == firstName && Father.LastName == lastName)
return Mother.FindParent(firstName, lastName);
return Father.FindParent(firstName, lastName);
static void Main(string[] args)
Person you = new Person("Filip", "Piecyk");
Person mom = new Person("Joanna", "Piecyk");
Person dad = new Person("Krzysztof", "Piecyk");
Person grandmaM = new Person("Jadwiga", "Lasok");
Person grandpaM = new Person("Ryszard", "Lasok");
Person grandmaF = new Person("Wanda", "Piecyk");
Person grandpaF = new Person("Piotr", "Piecyk");
Console.WriteLine("Drzewo rodzinne:");
Console.WriteLine("\nZnajdywanie Mamy:");
Person foundParent = you.FindParent("Joanna", "Piecyk");
Console.WriteLine(foundParent.FirstName + " " + foundParent.LastName);