Funktionen als Argumente

Id: funarg.tex,v 1.2 2004/11/16 12:32:07 waldmann Exp

void walk 
(void action (int), 
  tree * t) {
  void help (tree * t) {
    if (NULL != t) {
      action (t -> node);
      help (t -> left);
      help (t -> right);
    }
  }
  help (t);
}
void display (tree * t) {
  void show (int n) 
    { printf ("%d ", n); }
  walk (& show, t);
}

int count (tree * t) {
  int counter = 0;
  void one (int n) 
    { counter ++; }
  walk (& one, t);
  return counter;
}

Aufgabe: geht das in C? in Pascal? in Java?



Johannes Waldmann 2005-01-28