Du befindest dich hier: FSI Informatik » Prüfungsfragen und Altklausuren » Prüfungen im Bachelor-Studium (1. - 5. Semester) » aud » Forendiskussionen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige ÜberarbeitungNächste ÜberarbeitungBeide Seiten, nächste Überarbeitung | ||
pruefungen:bachelor:aud:loesung-miniklausur-14 [24.03.2015 17:46] – xenexi | pruefungen:bachelor:aud:loesung-miniklausur-14 [28.03.2016 15:35] – Code vereinfacht Marcel[Inf] | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
===== Forendiskussionen ===== | ===== Forendiskussionen ===== | ||
- | * TODO: Noch keiner. Falls welche angelegt, hier eintragen! :) | + | https://fsi.cs.fau.de/ |
===== Lösungsversuch ===== | ===== Lösungsversuch ===== | ||
Zeile 121: | Zeile 121: | ||
{ | { | ||
if( children[i] != null ) | if( children[i] != null ) | ||
- | | + | |
- | if( max < tmp ) max = tmp; | + | |
} | } | ||
- | | + | return max; |
- | else return max + 1; | + | |
} | } | ||
</ | </ | ||
Zeile 132: | Zeile 130: | ||
<code java> | <code java> | ||
static int longest(Tentree tree){ | static int longest(Tentree tree){ | ||
- | | + | // Basisfall |
+ | if (tree == null) { | ||
+ | return 0; | ||
+ | } | ||
int without = 0; | int without = 0; | ||
int tmp = 0; | int tmp = 0; | ||
- | for( int i = 0; i < 10; ++i ) | + | for ( int i = 0; i < 10; ++i ) |
{ | { | ||
- | | + | tmp = longest( children[i] ); |
- | | + | |
if( without < tmp ) | if( without < tmp ) | ||
without = tmp; | without = tmp; | ||
Zeile 155: | Zeile 155: | ||
tmp = height( children[i] ); | tmp = height( children[i] ); | ||
if( with < tmp ) { | if( with < tmp ) { | ||
- | n = with | + | n = with; |
with = tmp; | with = tmp; | ||
} else if( n < tmp ) { | } else if( n < tmp ) { | ||
Zeile 162: | Zeile 162: | ||
} | } | ||
} | } | ||
- | with += n + 2; | + | |
- | return Math.max(without, | + | |
+ | } else { | ||
+ | with = 0; // zB nur ein Pfad => auf 0 zurücksetzen | ||
+ | } | ||
+ | | ||
+ | } | ||
</ | </ |