There are two trees, both of which are pointing to the same data.
The key of the tree in question already is the frequency.
I ended up solving it by using a breadth first traversal function I came up with, the only difference being that I added a parameter and used the compare function from the header structure to determine weather or not to process the data in the node being traversed:
Code:
void BST_BreadthFind (BST_TREE* tree, void * dataPtr,
void (*process) (void* dataPtr))
{
QUEUE *q;
NODE *traverse, *newPtr;
newPtr = (NODE*)malloc(sizeof(NODE));
if (!newPtr)
return;
newPtr->right = NULL;
newPtr->left = NULL;
newPtr->dataPtr = dataPtr;
if(!tree->root)
return;
q = createQueue();
enqueue(q, tree->root);
while(!emptyQueue(q)){
dequeue(q, (void**)&traverse);
if(tree->compare(newPtr->dataPtr, traverse->dataPtr) == 0)
process(traverse->dataPtr);
if(traverse->left)
enqueue(q, traverse->left);
if(traverse->right)
enqueue(q, traverse->right);
}
destroyQueue(q);
free(newPtr);
return;
}
So my search function ended up looking like this:'
Code:
void searchFreq (BST_TREE *list)
{
WORD target, *wordPtr;
printf("\nEnter a frequency, enter -1 to exit: ");
target.count = scanInt();
while(target.count != -1)
{
wordPtr = (WORD*)BST_Retrieve (list, &target);
if(!wordPtr)
printf("No words with a frequency of %d were found\n", target.count);
else
BST_BreadthFind(list, &target, printResult);
printf("\nEnter a frequency, enter -1 to exit: ");
target.count = scanInt();
}
}//searchFreq