home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05113a < prev    next >
Text File  |  1991-03-23  |  713b  |  40 lines

  1. /*
  2.  * xrt.c - cross-reference table
  3.  */
  4. .
  5. .
  6.  
  7. struct treenode
  8.     {
  9.     char *word;
  10.     ln_seq lines;
  11.     treenode *left, *right;
  12.     treenode(unsigned);
  13.     };
  14.  
  15. treenode::treenode(unsigned n) : lines(n) { }
  16.  
  17. static treenode *addtree
  18.         (treenode *t, char *w, unsigned n)
  19.     {
  20.     int cond;
  21.  
  22.     if (t == 0)
  23.         {
  24.         t = new treenode(n);
  25.         t->word = new char[strlen(w) + 1];
  26.         strcpy(t->word, w);
  27.         t->left = t->right = 0;
  28.         }
  29.     else if ((cond = strcmp(w, t->word)) == 0)
  30.         t->lines.add(n);
  31.     else if (cond < 0)
  32.         t->left = addtree(t->left, w, n);
  33.     else
  34.         t->right = addtree(t->right, w, n);
  35.     return t;
  36.     }
  37. .
  38. .
  39.  
  40.