home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / windbase / windbase.exe / MEMSLC.3 / QUEUE.C < prev    next >
C/C++ Source or Header  |  1996-07-11  |  4KB  |  105 lines

  1. /*****************************************************************************\
  2. **                                                                           **
  3. **  WW     WW IIIIIIII NNN   NN DDDDDDD  BBBBBBB     AA     SSSSSS EEEEEEEE  **
  4. **  WW  W  WW    II    NNNN  NN DD    DD BB    BB  AA  AA  SS      EE        **
  5. **  WW  W  WW    II    NN NN NN DD    DD BBBBBBB  AAAAAAAA  SSSSSS EEEEEE    **
  6. **   WW W WW     II    NN  NNNN DD    DD BB    BB AA    AA      SS EE        **
  7. **    WWWWW   IIIIIIII NN   NNN DDDDDDD  BBBBBBB  AA    AA SSSSSS  EEEEEEEE  **
  8. **                                                                           **
  9. **   SSSSSS  OOOOOO  FFFFFFFF TTTTTTTT WW     WW    AA    RRRRRRR  EEEEEEEE  **
  10. **  SS      OO    OO FF          TT    WW  W  WW  AA  AA  RR    RR EE        **
  11. **   SSSSS  OO    OO FFFFF       TT    WW  W  WW AAAAAAAA RRRRRRR  EEEEEE    **
  12. **       SS OO    OO FF          TT     WW W WW  AA    AA RR   RR  EE        **
  13. **  SSSSSS   OOOOOO  FF          TT      WWWWW   AA    AA RR    RR EEEEEEEE  **
  14. **                                                                           **
  15. *********** NOTICE ************************************************************
  16. **        This file contains valuable trade secrets and proprietary          **
  17. **        assets of Windbase Software Inc.  Embodying substantial            **
  18. **        creative efforts and confidential information.  Unauthorized       **
  19. **        use, copying, decompiling, translating, disclosure or              **
  20. **        transfer, of any kind, is strictly prohibited.                     **
  21. **                                                                           **
  22. **        COPYRIGHT (C) 1992, 1993, 1994.  Windbase Software Inc.            **
  23. **        ALL RIGHTS RESERVED.                                               **
  24. \*****************************************************************************/
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <malloc.h>
  29.  
  30. #include "../memsl.h"
  31.  
  32. #if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
  33.   #ifdef WBSTDC
  34.     int main(int argc, char **argv)
  35.   #else
  36.     int main(argc, argv)
  37.       int argc;
  38.       char **argv;
  39.   #endif
  40. #else
  41.   #ifdef WBSTDC
  42.     int main(void)
  43.   #else
  44.     int main()
  45.   #endif
  46. #endif
  47.   {
  48.     FILE *file;
  49.     WBQUEUE *queue;
  50.     char str[21], item[21], *strptr;
  51.  
  52.     WBTrcMainEntry();
  53.  
  54. #if 1  /* Queue using an array and having the queue copy the items */
  55.  
  56.     printf("Queue using an array:\n");
  57.     if ((queue = WBQueueOpen(NULL,21,50,1)) != NULL)
  58.       {
  59.     printf("\nQueue is empty: %s\n",WBQueueIsEmpty(queue)?"Yes":"No");
  60.     if ((file = fopen("data.dat","r")) != NULL)
  61.       {
  62.         while (fgets(str,20,file))
  63.           {
  64.         if (WBQueuePush(queue,str) == 0)
  65.                   {
  66.                     printf("Popping: %s",WBQueuePop(queue,item));
  67.                     WBQueuePush(queue,str);
  68.                   }
  69.               }
  70.             printf("\nQueue is empty: %s\n",WBQueueIsEmpty(queue)?"Yes":"No");
  71.             while ((strptr = WBQueuePop(queue,item)) != NULL)
  72.               printf("%s  %s",strptr, item);
  73.         fclose(file);
  74.           }
  75.         printf("\nQueue is empty: %s\n",WBQueueIsEmpty(queue)?"Yes":"No");
  76.         WBQueueClose(queue);
  77.       }
  78. #else   /* Queue using a linked list */
  79.  
  80.     printf("Queue using a linked list:\n");
  81.     if ((queue = WBQueueOpen(NULL,0,0,0)) != NULL)
  82.       {
  83.         if ((file = fopen("data.dat","r")) != NULL)
  84.           {
  85.             while (fgets(str,20,file))
  86.               {
  87.                 if ((strptr = malloc(strlen(str)+1)) != NULL)
  88.                   {
  89.                     strcpy(strptr,str);
  90.                     WBQueuePush(queue,strptr);
  91.                   }
  92.               }
  93.             fclose(file);
  94.             while ((strptr = WBQueuePop(queue,NULL)) != NULL)
  95.               {
  96.                 printf("%s",strptr);
  97.                 free(strptr);
  98.               }
  99.           }
  100.         WBQueueClose(queue);
  101.       }
  102. #endif
  103.     WBTrcReturn(0,0,("0"));
  104.   }
  105.