Vincent Vajnovszki
On the Loopless Generation of Binary Tree Sequences
Information Processing Letters, 68 (1998), 113-117.
Abstract

#include

int w[20], d[20],
    l[20],
    R[20],L[20],
    F[20],  
    n,p,N=1;
    
init()
{ int i;
  printf("donnez n"); scanf("%d",&n);
  p=n;
  for(i=1;i<=n;i++)
  {  w[i]=1;
     d[i]=1;
     l[i]=i-1;
  }  
  l[n+1]=n;
  /* L */
  for(i=1;i<=n;i++) L[i]=0;
 
  /* R */
  for(i=1;i<=n+1;i++) R[i]=i+1;
  R[n]=0;
  
  /* F */
  F[1]=0;
  for(i=2;i<=n;i++)F[i]=i-1;  
}

type()
{ int i;
  printf("%d\t",N);
  for(i=1;i<=n;i++) printf("%d ",w[i]);
  printf("\n");
}

inc(int pos,int dir)
{ int u,v;
  if(dir==1) 
 { /*w[pos]++;*/
    v=pos; u=F[v];
    
    w[pos]=w[pos]+w[pos-w[pos]];
    
    /******/
    if( L[F[u]]==u ) L[F[u]]=v;
    else R[F[u]]=v;
    F[v]=F[u];
    /******/
    R[u]=L[v];
    F[L[v]]=u;
    /******/
    F[u]=v;
    L[v]=u; 
 }
 else 
 {  w[pos]=w[pos]-w[L[pos]];
 
    v=pos; u=L[v];
   
   /******/
    if( L[F[v]]==v) L[F[v]]=u;
    else R[F[v]]=u;
    F[u]=F[v];
    /******/
    L[v]=R[u];
    F[R[u]]=v;
    /******/
    F[v]=u;
    R[u]=v; 
  }
}

succ()
{ l[n+1]=n;
  inc(p,d[p]);
  if(w[p]==1 || w[p]==p ) 
  {   d[p]=-d[p];
      l[p+1]=l[p];
      l[p]=p-1;    
   }    
  p=l[n+1];   
}

main()
{ init();
  while(p>=2)
  { type();
    N++;
    succ();       
  }
  type();  
}