home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_09 / 9n09024a < prev    next >
Text File  |  1991-07-21  |  2KB  |  61 lines

  1.  
  2. /* --------------------------------------------------------------
  3.  
  4. FUNCTION LOCATE_NODE: The steps to locating a node in the list are:
  5.  
  6. A.  Traverse the whole list starting at the root.
  7.  
  8. B.  If the string we are searching for is alphabetically equal to the 
  9. current on in the list return that list entry's address.
  10.  
  11. C.  Else if the new string is less than that in the list the one we 
  12. are searching for isn't in the list.  So is we were looking for
  13. an exact match indicate it wasn't found.  For an inexact match
  14. return the address of the previous node (which must be less than
  15. the one we are searching for).
  16.  
  17. D.  The match may still be coming so keep looking.
  18.  
  19. E.  We've reached the end of the list so is we were looking for
  20. an exact match indicate it wasn't found.  For an inexact match
  21. return the address of the previous node (which must be less than
  22. the one we are searching for).
  23.  
  24. -------------------------------------------------------------- */
  25.  
  26. Node *locate_node(const char *pstring, int match)
  27. {
  28.     Node *ptmp_node = proot_node;
  29.     Node *pold_node = NULL;
  30.     int comp;
  31.  
  32. /*A*/    while (ptmp_node != NULL) {
  33.         comp = strcmp(pstring, ptmp_node->pstring);
  34. /*B*/        if (comp == 0) {
  35.             return ptmp_node;
  36.         }
  37. /*C*/        else if (comp < 0) {
  38.             if (match == EXACT) {
  39.                 return NULL;
  40.             }
  41.             else {
  42.                 return ptmp_node->pbwd;
  43.             }
  44.         }
  45. /*D*/        else {
  46.             pold_node = ptmp_node;
  47.             ptmp_node = ptmp_node->pfwd;
  48.         }
  49.     }
  50.  
  51. /*E*/    if (match == EXACT) {
  52.         return NULL;
  53.     }
  54.     else {
  55.         return pold_node;
  56.     }
  57. }
  58.  
  59. /* ----------------------------------------------------------- */
  60.  
  61.