示例#1
0
BTreeNode* BTreeSearch(BTreeNode* bt, BTData target) {
	if(bt == NULL)
		return NULL;
	if(bt->data == target)
		return bt;
	BTreeSearch(bt->left, target);
	BTreeSearch(bt->right, target);
}
示例#2
0
void DataBaseInsert(char secondName[20], char initials[5], char number[15], char adress[40])
{
	Abonent* newAbonent = new Abonent;
	strcpy(newAbonent->secondName, secondName);
	strcpy(newAbonent->initials, initials);
	strcpy(newAbonent->number, number);
	strcpy(newAbonent->adress, adress);
	int resultIndex = 1;
	TNode *resultNode = BTreeSearch(secondNameBTree->root, secondName, &resultIndex);
	if (resultIndex == -1)
	{
		TKey* k = new TKey;
		k->abonentsList.push_back(newAbonent);
		strcpy(k->key, secondName);
		BTreeInsert(secondNameBTree, k);
	}
	else
	{
		resultNode->keyArray[resultIndex].abonentsList.push_back(newAbonent);
	}
	resultNode = BTreeSearch(adressBTree->root, adress, &resultIndex);
	if (resultIndex == -1)
	{
		TKey* k = new TKey;
		k->abonentsList.push_back(newAbonent);
		strcpy(k->key, adress);
		BTreeInsert(adressBTree, k);
	}
	else
	{
		resultNode->keyArray[resultIndex].abonentsList.push_back(newAbonent);
	}
	resultNode = BTreeSearch(numberBTree->root, number, &resultIndex);
	if (resultIndex == -1)
	{
		TKey* k = new TKey;
		k->abonentsList.push_back(newAbonent);
		strcpy(k->key, number);
		BTreeInsert(numberBTree, k);
	}
	else
	{
		resultNode->keyArray[resultIndex].abonentsList.push_back(newAbonent);
	}
}
示例#3
0
TNode *BTreeInsertRoot(BTree *pTree, const void *pData)
{
    // check for duplicate key
    if (BTreeSearch(pTree, pData) != NULL)
    {
        return NULL;
    }

    insertRootRecursive(&pTree->pRoot, pData, pTree->compare);
    return pTree->pRoot;
}
示例#4
0
TNode* BTreeSearch(TNode* x, char* key, int* resultIndex)
{
	int i = 0;
	while (i <= x->keyNumber - 1 && strcmp(key, x->keyArray[i].key) > 0)
		i++;
	if (i < x->keyNumber && strcmp(key,x->keyArray[i].key)==0)
	{

		*resultIndex = i;
		return x;
	}
	else
	{
		if (x->isLeaf == true)
		{
			*resultIndex = -1;
			return 0;
		}
		else
			BTreeSearch(x->childrenArray[i], key, resultIndex);
	}
}
示例#5
0
extern "C" __declspec(dllexport) char*** __stdcall DataBaseSearchPhoneNumber(char phoneNumber[20])
{
	int resultIndex = 1;
	TNode* resultNode = BTreeSearch(numberBTree->root, phoneNumber, &resultIndex);
	if (resultIndex != -1)
	{
		std::vector<Abonent*> abonentsList = resultNode->keyArray[resultIndex].abonentsList;
		int vectorSize = abonentsList.size();
		char*** exitArray = new char**[vectorSize];
		for (int i = 0; i < vectorSize; i++)
		{
			char** resultArray = new char*[4];
			resultArray[0] = resultNode->keyArray[resultIndex].abonentsList[i]->secondName;
			resultArray[1] = resultNode->keyArray[resultIndex].abonentsList[i]->initials;
			resultArray[2] = resultNode->keyArray[resultIndex].abonentsList[i]->adress;
			resultArray[3] = resultNode->keyArray[resultIndex].abonentsList[i]->number;
			exitArray[i] = resultArray;
		}
		return exitArray;
	}
	return 0;
}