class Person { int alder = 0; Person far = null; Person mor = null; Person(int a, Person f, Person m) { alder = a; far = f; mor = m; } public Person finnEldstekjenteOpphav() { if (far == null && mor == null) { return this; } else if (far == null) { return mor.finnEldstekjenteOpphav(); } else if (mor == null) { return far.finnEldstekjenteOpphav(); } else { Person farsEldste = far.finnEldstekjenteOpphav(); Person morsEldste = mor.finnEldstekjenteOpphav(); if (farsEldste.alder > morsEldste.alder) return farsEldste; return morsEldste; } } public static void main(String[] args) { Person olda = new Person(200, null, null); //ikke en del av treet Person olga = new Person(160, null, null); Person ingunn = new Person(140, null, olga); Person alf = new Person(137, null, olga); Person aase = new Person(140, null, null); Person arvid = new Person(139, null, null); Person are = new Person(100, arvid, aase); Person noa = new Person(100, arvid, ingunn); Person ada = new Person(97, arvid, aase); Person ida = new Person(67, null, ada); Person randi = new Person(60, noa, null); Person anne = new Person(48, null, ida); Person rolf = new Person(45, null, randi); Person per = new Person(15, anne, rolf); System.out.println(per.finnEldstekjenteOpphav().alder); } }