P148: Enumeration of all trees with $n$ vertices and $d$ diameter

P148: Enumeration of all trees with $n$ vertices and $d$ diameter
Input:
Integers $n$ and $d$.
Output:
All trees with $n$ vertices and $d$ diameter.
Complexity:
$O(1)$ time per tree with $O(n)$ space.
Comment:
By using the algorithm for each $d = 2, \dots, n-1$, all trees can be enumerated.
Reference:
[Nakano2004] (Bibtex)