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
/
TAVLTREE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-30
|
6KB
|
193 lines
/*****************************************************************************\
** **
** 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. Windbase Software Inc. **
** ALL RIGHTS RESERVED. **
\*****************************************************************************/
#include <stdio.h>
#include <string.h>
#ifdef HAS_UNISTD_H
# include <unistd.h>
#else
# include <stdlib.h>
#endif
#include "../memsl.h"
WBTAVL *tavl;
#ifdef WBSTDC
int Compare(void *nullitem, char *item1, char *item2)
#else
int Compare(nullitem, item1, item2)
void *nullitem;
char *item1,
*item2;
#endif
{
WBTrcEntry(0,"Compare",("%p, %s, %s",nullitem,item1?item1:"NULL",item2?item2:"NULL"));
nullitem = nullitem;
WBTrcReturn(0,strcmp(item1,item2),("%d",strcmp(item1,item2)));
}
#ifdef WBSTDC
void Delete(void *nullitem, char *item)
#else
void Delete(nullitem, item)
void *nullitem;
char *item;
#endif
{
WBTrcEntry(0,"Delete",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
free(item);
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void Execute(void *nullitem, char *item)
#else
void Execute(nullitem, item)
void *nullitem;
char *item;
#endif
{
WBTrcEntry(0,"Execute",("%p, %s",nullitem,item?item:"NULL"));
nullitem = nullitem;
printf("Execute(): %s\n",item);
WBTrcVReturn(0,(""));
}
#ifdef WBSTDC
void PTree(struct tavl_tree *root, int len, int right)
#else
void PTree(root, len, right)
struct tavl_tree *root;
int len;
int right;
#endif
{
WBTrcEntry(0,"PTree",("%p, %d, %d",root,len,right));
if (root)
{
if (root->left && root->ltag == 0)
PTree(root->left,len+3,0);
if (len)
{
if (right)
printf("%*s--\\ ",len,"");
else
printf("%*s--/ ",len,"");
}
printf("%d:%s\n",root->bal,(char *)root->item);
if (root->bal < -1 || root->bal > 1) /* Should never happen */
{
printf("Error: balance factor.\n");
exit(1);
}
if (root->right && root->rtag == 0)
PTree(root->right,len+3,1);
}
WBTrcVReturn(0,(""));
}
#if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
#ifdef WBSTDC
int main(int argc, char **argv)
#else
int main(argc, argv)
int argc;
char **argv;
#endif
#else
#ifdef WBSTDC
int main(void)
#else
int main()
#endif
#endif
{
FILE *file;
char str[256], *strptr;
WBTrcMainEntry();
if ((tavl = WBTAVLOpen(NULL)) != NULL)
{
WBTAVLDuplicates(tavl,1);
#ifdef FUNCTCAST
WBTAVLCompareF(tavl,NULL,(int (*)(void *, void *, void *))Compare);
WBTAVLDeleteF(tavl,NULL,(void (*)(void *, void *))Delete);
WBTAVLExecuteF(tavl,NULL,(void (*)(void *, void *))Execute);
#else
WBTAVLCompareF(tavl,NULL,(int (*)())Compare);
WBTAVLDeleteF(tavl,NULL,(void (*)())Delete);
WBTAVLExecuteF(tavl,NULL,(void (*)())Execute);
#endif
if ((file = fopen("data.dat","r")) != NULL)
{
while (fgets(str,255,file))
{
if (str[strlen(str)-1] == '\n')
str[strlen(str)-1] = 0;
if ((strptr = malloc(strlen(str)+1)) != NULL)
{
strcpy(strptr,str);
if (WBTAVLAdd(tavl,strptr) == 1)
printf("Added: %s\n",str);
}
}
fclose(file);
printf("==========================\n");
PTree(tavl->root,0,0);
WBTAVLExecute(tavl);
if ((file = fopen("data.dat","r")) != NULL)
{
while (fgets(str,255,file))
{
if (str[strlen(str)-1] == '\n')
str[strlen(str)-1] = 0;
if (WBTAVLDelete(tavl,str) == 0)
printf("%c%c%s not found\n",7,7,str);
else
printf("Deleted: %s\n",str);
}
fclose(file);
}
}
WBTAVLClose(tavl);
}
WBTrcReturn(0,0,("0"));
}