Exemple #1
0
patch
compactify (patch p) {
  switch (get_type (p)) {
  case PATCH_COMPOUND:
    {
      double a= 0;
      for (int i=0; i<N(p); i++)
	if (get_type (p[i]) != PATCH_AUTHOR) a= -1;
	else if (a == 0) a= get_author (p[i]);
	else if (a != get_author (p[i])) a= -1;
      if (a <= 0) {
	array<patch> r;
	insert (r, p);
	if (N(r) == 1) return r[0];
	return patch (r);
      }
      else {
	array<patch> r;
	for (int i=0; i<N(p); i++) insert (r, p[i][0]);
	if (N(r) == 1) return patch (a, r[0]);
	return patch (a, patch (r));
      }
    }
  case PATCH_BRANCH:
    if (N(p) == 1) return p[0];
    else {
      int i, n= N(p);
      array<patch> r (n);
      for (i=0; i<n; i++) r[i]= compactify (p[i]);
      return patch (true, r);
    }
  case PATCH_AUTHOR:
    return patch (get_author (p), compactify (p[0]));
  }
  return p;
}
Exemple #2
0
main() {
  int post[SIZE];
  int pre[SIZE];
  int isFree[SIZE];
  int list;
  int free;
  list = 7;
  post[7] = 0; pre[7] = -1; isFree[7] = 0; 
  post[0] = 3; pre[0] = 7;  isFree[0] = 0;
  post[3] = 6; pre[3] = 7;  isFree[3] = 0;
  post[6] = 2; pre[6] = 3;  isFree[6] = 0;
  post[2] = 5; pre[2] = 6;  isFree[2] = 0;
  post[5] = -1; pre[5] = 2; isFree[5] = 0;
  free = 4;
  post[4] = 1; pre[4] = -1; isFree[4] = 1;
  post[1] = -1; pre[1] = 4; isFree[1] = 1;

  trav(free, post);
  trav(list, post);

  compactify(pre, post, isFree, &list, &free);
  trav(free, post);
  trav(list, post);
}