On Jun 29, 10:50 pm, sharad kumar <[email protected]> wrote:
> @gene
> i tried but unable to extend it to n ary tree...can u plzz extend it to n
> ary ...
> thnx in advance..
// check a for symmetry
boolean is1(a)
{
if (a == null) return true;
for (i = 0, j = a->n_children - 1; i < j; i++, j--)
if (!is2(a->child[i], a->child[j])
return false;
return i == j ? is1(a->child[i]) : true;
}
// check that pair a and b are mirror images
boolean is2(a, b)
{
if (a == null && b == null) return true;
if (a != null && b != null && a->key == b->key && a->n_children == b-
>n_children) {
for (i = 0, j = a->n_children - 1; j >= 0; i++, j--)
if (!is2(a->child[i], b->child[j])
return false;
return true;
}
return false;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.