// Poor but correct code: int MaxLeaf (itree t) { int n = 0; int *p; CountLeaves (t, &n); p = (int *) malloc (n * sizeof (int)); CollectLeaves (t, p); p = p - n; SortLeaves (p, n); return * (p + n - 1); } void CountLeaves (itree t, int *n) { if (IsLeaf (t)) *n = *n + 1; else { CountLeaves (Left (t), n); CountLeaves (Right (t), n); } } void CollectLeaves (itree t, int *&p) { if (IsLeaf (t)) * (p++) = Label (t); else { CollectLeaves (Right (t), p); CollectLeaves (Left (t), p); } } void SortLeaves (int *p, int n) { int *r = p + n; for (int i = 0; i < n; i = i + 1, p = p + 1) { for (int *q = p; q < r; q++) if (*q < *p) { int temp = *p; *p = *q; *q = temp; } } }