- Codice:
profond(Tree t)
integer max <-- 0
Tree u <-- t.leftmostChild() % primo figlio (a sx)
while u != nil do
integer t <-- profond(u) + 1
if t > max then max <-- t
u <-- u.rightSibling() % prossimo fratello (da sx a dx)
return max
profond(Tree t)
integer max <-- 0
Tree u <-- t.leftmostChild() % primo figlio (a sx)
while u != nil do
integer t <-- profond(u) + 1
if t > max then max <-- t
u <-- u.rightSibling() % prossimo fratello (da sx a dx)
return max
contaNodi(Tree t)
tot <-- 1
Tree s <-- t.leftmostChild()
while ( s != nil ) do
tot <-- tot + contaNodi(s)
s <-- s.rightSibling()
return tot
contaFoglie(Tree s)
if (s.leftmostChild = nil) return 1
tot <-- 0
Tree t <-- s.leftmostChild()
while ( t != nil ) do
tot <-- tot + contaFoglie(t)
t <-- t.rightSibling()
return tot
Visitano il forum: Nessuno e 1 ospite