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 / memslcpp.3 / tree2.cpp < prev    next >
C/C++ Source or Header  |  1995-11-04  |  4KB  |  113 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, 1995.  Windbase Software Inc.     **
  23. **       ALL RIGHTS RESERVED.                                              **
  24. \***************************************************************************/
  25.  
  26. /*
  27. ** Binary Tree - Non Templates Version
  28. */
  29.  
  30. int WBCompareFunct(void *nullitem, char *item1, char *item2)
  31.   {
  32.     nullitem = nullitem;
  33.     return(strcmp(item1,item2));
  34.   }
  35.  
  36. void WBExecuteFunct(void *nullitem, char *item)
  37.   {
  38.     nullitem = nullitem;
  39.     cout << "ExecuteFunct: " << item << "\n";
  40.   }
  41.  
  42. void WBDeleteFunct(void *nullitem, char *item)
  43.   {
  44.     nullitem = nullitem;
  45.     item = item;
  46.   }
  47.  
  48. void PrintTree(int level, int left, char *item)
  49.   {
  50.     if (level)
  51.       {
  52.     cout.width(level*2);
  53.     cout.fill(' ');
  54.     if (left)
  55.       cout << "/" << "-- ";
  56.     else
  57.       cout << "\\" << "-- ";
  58.     cout << item << "\n";
  59.       }
  60.     else
  61.       cout << item << "\n";
  62.   }
  63.  
  64. main()
  65.   {
  66.     WBTree tree;
  67.     ifstream infile("data2.dat");
  68.     char str[81], *strptr;
  69.     int i = 0;
  70.  
  71.     tree.SetCompare(NULL,(int (*)(void *, void *, void *))WBCompareFunct);
  72.     tree.SetExecute(NULL,(void (*)(void *, void *))WBExecuteFunct);
  73.     tree.SetDelete(NULL,(void (*)(void *, void *))WBDeleteFunct);
  74.  
  75.     if ((!infile) == 0 && infile.rdbuf()->is_open())
  76.       {
  77.     while (infile.getline(str,80))
  78.       {
  79.         cout << "Adding " << ++i << "\n";
  80.         if ((strptr = new char [strlen(str)+1]) != NULL)
  81.           {
  82.         strcpy(strptr,str);
  83.         tree += strptr;
  84.           }
  85.       }
  86.  
  87.     cout << "IsEmpty: " << (tree.IsEmpty() ? "Yes" : "No") << "\n";
  88.     cout << "NumItems: " << tree.NumItems() << "\n";
  89.  
  90.     tree.InOrder();
  91.     tree.InOrderPrint((void (*)(int, int, void *))PrintTree);
  92.     infile.close();
  93.       }
  94.  
  95.     infile.open("data2.dat");
  96.     if ((!infile) == 0 && infile.rdbuf()->is_open())
  97.       {
  98.     while (infile.getline(str,80))
  99.       cout << "Search: " << (char *) tree.Search(str) << "\n";
  100.  
  101.     infile.close();
  102.       }
  103.  
  104.     infile.open("data2.dat");
  105.     if ((!infile) == 0 && infile.rdbuf()->is_open())
  106.       {
  107.     while (infile.getline(str,80))
  108.       cout << "Delete: " << str << " " << tree.Delete(str) << "\n";
  109.       }
  110.  
  111.     return(0);
  112.   }
  113.