home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_01 / 9n01074a < prev    next >
Text File  |  1990-02-02  |  1KB  |  40 lines

  1.  
  2.    void ADDRESS_BOOK_TREE::alloc_data(NODE *to_node, void *from_data)
  3.       {
  4.       ADDRESS_BOOK_ENTRY *to = to_node->data;
  5.       ADDRESS_BOOK_ENTRY *from = from_data;
  6.  
  7.       to->name = new char[strlen(from->name)+1];
  8.       strcpy(to->name, from->name);
  9.  
  10.       to->street_address = new char[strlen(from->street_address)];
  11.       strcpy(to->street_address, from->street_address);
  12.  
  13.       // etc. for other fields in an ADDRESS_BOOK_ENTRY
  14.       }
  15.  
  16.    void ADDRESS_BOOK_TREE::delete_data(NODE *nptr)
  17.       {
  18.       ADDRESS_BOOK_ENTRY aptr = nptr->data;
  19.  
  20.       delete to->name;
  21.       delete to->street_address;
  22.       delete to->city;
  23.       delete to->state;
  24.       zip = 0L;
  25.       }
  26.  
  27.    void ADDRESS_BOOK_TREE::compare(void *v1, void *v2, size_t size)
  28.       {
  29.       // This function compares the names in each entry, returning
  30.       // <0 if d1->name < d2->name, 0 if d1->name == d2->name, 
  31.       // and >0 if d1->name > d2->name.  This is very easy to do 
  32.       // by using the strcmpl() function.  In this case the 'size'
  33.       // argument is irrelevant.
  34.  
  35.       ADDRESS_BOOK_ENTRY *d1 = v1, *d2 = v2;
  36.  
  37.       return strcmpl(d1->name, d2->name);
  38.       }
  39.  
  40.