home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************\
- ** **
- ** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
- ** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
- ** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
- ** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
- ** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
- ** **
- ** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
- ** SS OO OO FF TT WW W WW AA AA RR RR EE **
- ** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
- ** SS OO OO FF TT WW W WW AA AA RR RR EE **
- ** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
- ** **
- ********** NOTICE ***********************************************************
- ** This file contains valuable trade secrets and proprietary **
- ** assets of Windbase Software Inc. Embodying substantial **
- ** creative efforts and confidential information. Unauthorized **
- ** use, copying, decompiling, translating, disclosure or **
- ** transfer, of any kind, is strictly prohibited. **
- ** **
- ** COPYRIGHT (C) 1992, 1993, 1994, 1995. Windbase Software Inc. **
- ** ALL RIGHTS RESERVED. **
- \***************************************************************************/
-
- /*
- ** AVL Balanced Binary Tree - Templates Version
- */
-
- template <class USRDEF>
- class MyAVLTree : public WBAVLTree<USRDEF>
- {
- int WBCompareFunct(void *nullitem, char *item1, char *item2)
- {
- nullitem = nullitem;
- return(strcmp(item1,item2));
- }
-
- void WBExecuteFunct(void *nullitem, char *item)
- {
- nullitem = nullitem;
- cout << "ExecuteFunct: " << item << "\n";
- }
-
- void WBDeleteFunct(void *nullitem, char *item)
- {
- nullitem = nullitem;
- cout << "DeleteFunct: " << item << "\n";
- }
- };
-
- void PrintTree(int bal, int level, int left, char *item)
- {
- if (level)
- {
- cout.width(level*2);
- cout.fill(' ');
- if (left)
- cout << "/" << "-- ";
- else
- cout << "\\" << "-- ";
- cout << bal << ":" << item << "\n";
- }
- else
- cout << bal << ":" << item << "\n";
- }
-
- main()
- {
- MyAVLTree<char *> tree;
- ifstream infile("data.dat");
- char str[81], *strptr;
- int i = 0;
-
- if ((!infile) == 0 && infile.rdbuf()->is_open())
- {
- while (infile.getline(str,80))
- {
- cout << "Adding " << ++i << "\n";
- if ((strptr = new char [strlen(str)+1]) != NULL)
- {
- strcpy(strptr,str);
- tree += strptr;
- }
- }
-
- cout << "IsEmpty: " << (tree.IsEmpty() ? "Yes" : "No") << "\n";
- cout << "NumItems: " << tree.NumItems() << "\n";
-
- tree.InOrder();
- tree.InOrderPrint(PrintTree);
- infile.close();
- }
-
- infile.open("data.dat");
- if ((!infile) == 0 && infile.rdbuf()->is_open())
- {
- while (infile.getline(str,80))
- cout << "Search: " << tree.Search(str) << "\n";
-
- infile.close();
- }
-
- infile.open("data.dat");
- if ((!infile) == 0 && infile.rdbuf()->is_open())
- {
- while (infile.getline(str,80))
- cout << "Delete: " << str << " " << tree.Delete(str) << "\n";
- }
-
- return(0);
- }
-