home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 308_02 / vlist.cpp < prev   
C/C++ Source or Header  |  1990-09-22  |  2KB  |  94 lines

  1.  
  2. /*
  3.     TITLE:        VirtualList test driver;
  4.     DESCRIPTION:    "Test stub for C++ Virtual linked-list.
  5.             ( Class VirtualList )";
  6.  
  7.     VERSION:        1.0;
  8.     DATE:           9/21/90;
  9.     COMPILERS:      Borland Turbo C++ V.1.0;
  10.     KEYWORDS:    test driver virtual list;
  11.     FILENAME:    Vlist.cpp;
  12.     SEE-ALSO:    VirtList.cpp, VirtList.hpp;
  13.  
  14.     AUTHOR:         Michael Kelly
  15.             254 Gold St. Boston, Ma. 02127
  16.             Copyright 1990;
  17.  
  18.     COPYRIGHT:    This code may not be commercially distributed
  19.             without prior arrangement with the author.  It
  20.             may be used by programmers, without royalty, for
  21.             their personal programs and for "one of a kind"
  22.             or "custom" applications, provided that said
  23.             programmers assume all liability concerning
  24.             same.
  25. */
  26.  
  27. #include "virtlist.hpp"
  28.  
  29. #define BLOCK_SIZE 6200
  30. char buffer[BLOCK_SIZE];
  31.  
  32. struct phrases  {
  33.     char num_str[16];
  34.     char junk[6000];
  35. };
  36.  
  37.  
  38. int main(void)
  39. {
  40.     int i;
  41.     VirtualList v_list;
  42.     VirtualList *virtual_list = new VirtualList;
  43.  
  44.     char crap[24];
  45.     phrases *a_phrase = new phrases;
  46.     if(! a_phrase)
  47.     err_exit("Cannot allocate a_phrase");
  48.  
  49.   if(! virtual_list->get_entries())  {
  50.  
  51.     for(i = 49;i > -1;i--)  {
  52.     sprintf(a_phrase->num_str, "%03d", i);
  53.  
  54.     if(! virtual_list->add_item(a_phrase, sizeof(phrases)))  {
  55.         printf("\ndied on loop %d\n", 49 - i);
  56.         err_exit("Couldn't add a phrase");
  57.     }
  58.  
  59.     }
  60.   }
  61.  
  62.     for(i = 0;i < 50;i++)  {
  63.     sprintf(crap, "%02d", i);
  64.     strcat(crap, " crap");
  65.     if(! v_list.add_item(crap, 24))
  66.         err_exit("Couldn't add to Crap");
  67.     }
  68.  
  69.     printf("\n\n\tVirtual List Sorted ...\n\n");
  70.     if(! virtual_list->sort()  ||  virtual_list->error() == NO_MEM)
  71.     printf("\n\tSort Failed!\n");
  72.  
  73.     do    {
  74.  
  75.     if(! virtual_list->get_item(buffer))
  76.         break;
  77.     printf("%s\n", buffer);
  78.     }
  79.     while(virtual_list->next());
  80.  
  81.  
  82.     i = virtual_list->get_entries();
  83.     printf("\n\tList of %d items\n\n", i);
  84.  
  85.     v_list.first();
  86.  
  87.     while(v_list.remove_item(crap))
  88.     printf("%s\n", crap);
  89.  
  90.     delete a_phrase;
  91.     delete virtual_list;
  92.     return(EXIT_SUCCESS);
  93. }
  94.