TreeNode* searchNode(Tree* treePtr,void* parentData){ TreeNode* parent; TreeNode* root = treePtr->root; if(NULL == root) return NULL; if(treePtr->compare(root->data, parentData)) return root; parent = compareNodes(root->children, treePtr->compare, parentData); return parent; };
TreeNode* compareNodes(List* list, compareFunc* compareFunc, void* parentData){ Iterator *iterator = getIterator(list); TreeNode* treeNode,result; List *listOfChildren = create(); if(0 == iterator->hasNext(iterator)){ return NULL; }; insertChildern(treeNode,listOfChildren); while(iterator->hasNext(iterator)){ treeNode = (TreeNode*)iterator->next(iterator); if(compareFunc(treeNode->data,parentData)){ return treeNode; }; }; return compareNodes(listOfChildren,compareFunc,parentData); };
/*Procura por uma palavra dentro da árvore*/ static int seekWord (char *searchedWord, link h){ int treeWay = 0; int result = 0; if (compareNodes(h,z)) return 0; treeWay = compareKeys(searchedWord,h->englishWord.word); if (treeWay == 0) return 1; else if(treeWay < 0) result = seekWord(searchedWord,hl); else if (treeWay > 0) result = seekWord(searchedWord,hr); return result; }
/*Funćão de busca semelhante*/ static link seekLemmaText (char *searchedWord, link h){ int treeWay = 0; link result; if (compareNodes(h,z)) return NULL; treeWay = compareKeys(searchedWord,h->englishWord.word); if (treeWay == 0) return h; else if(treeWay < 0) result = seekLemmaText(searchedWord,hl); else if (treeWay > 0) result = seekLemmaText(searchedWord,hr); return result; }
static link LLRBinsert(link h, EnglishWord newWord){ Key v = makeKey(newWord); int val = 0; if (compareNodes(h,z)) return NEW(newWord, z, z, 1); val = compareKeys(v,makeKey(h->englishWord)); if ( val < 0) hl = LLRBinsert(hl, newWord); else hr = LLRBinsert(hr, newWord); if (hr->red && !hl->red) h = rotL(h); if (hl->red && hll->red) h = rotR(h); if (hl->red && hr->red) colorFlip(h); return h; }