void test_search_element_in_the_tree_from_one_node(){ Tree tree = createTree(compareInteger); Iterator result; int data[5] = {1,2,3,4,5}; ASSERT(insertTree(&tree, NULL, &data[0])); ASSERT(insertTree(&tree, &data[0], &data[1])); ASSERT(insertTree(&tree, &data[1], &data[2])); ASSERT(insertTree(&tree, &data[2], &data[3])); ASSERT(insertTree(&tree, &data[3], &data[4])); ASSERT(searchTreeNode(&tree,&data[4])); }
void test_get_child_after_inserting_under_parent(){ Tree tree = createTree(compareInteger); int arr[] = {1,2,3,4}; Iterator result; insertTree(&tree, NULL, &arr[0]); insertTree(&tree, &arr[0], &arr[1]); insertTree(&tree, &arr[1], &arr[2]); insertTree(&tree, &arr[2], &arr[3]); result = getChildren(&tree, &arr[1]); ASSERT(3 == *(int*)result.next(&result)); }
void test_get_children_from_two_different_(){ Tree tree = createTree(compareInteger); int arr[] = {1,2,3,4}; Iterator result; insertTree(&tree, NULL, &arr[0]); insertTree(&tree, &arr[0], &arr[1]); insertTree(&tree, &arr[1], &arr[2]); insertTree(&tree, &arr[2], &arr[3]); result = getChildren(&tree, &arr[1]); ASSERT(3 == *(int*)result.next(&result)); result = getChildren(&tree, &arr[2]); ASSERT(4 == *(int*)result.next(&result)); }
void insertTree(Bst* bst, Bst* insertnode) { //노드를 삽입하는 함수 if(strcmp(bst->value,insertnode->value)>0) { //문자열이기 때문에 strcmp를 사용하여 크기비교 if(bst->leftchild==NULL) //작은 값이기 때문에 왼쪽이 널이면 대입하고 아니면 재귀로 계속 부른다. bst->leftchild=insertnode; else insertTree(bst->leftchild, insertnode); } else { if(bst->rightchild==NULL) //입력 문자열이 큰값일때 오른쪽을 확인하고 대입하고 재귀로 부른다. bst->rightchild=insertnode; else insertTree(bst->rightchild, insertnode); } }
void binomial_queue<T>::addTree(tree_reference treeToAdd) { if (empty() == false) addTreeNotEmpty(treeToAdd); else insertTree(treeToAdd); }
void main(void) { int i; Bst* bst=allocationTree("one"); //첫 루트 트리노드를 생성 char* data; //입력시 사용자 입력을 받을 변수 char removedata[5]; //삭제시 사용자 입력을 받을 변수 inorderprint(bst); printf("\n"); for(i=1; i<=19; i++) { //19번 반복하면서 twet까지 입력한다. printf("새로운 노드 입력 : "); data=(char*)malloc(sizeof(char)*5); scanf("%s", data); insertTree(bst, allocationTree(data)); inorderprint(bst); printf("\n"); } for(i=1; i<=20; i++) { //총 20번 입력의 역순과 입력순서로 삭제하기 위한 반복문이다. printf("삭제 할 노드 입력 : "); scanf("%s", removedata); removeTree(bst, removedata); inorderprint(bst); printf("\n"); leftdepth=0; //삭제할 노드의 양쪽 서브트리를 비교하기 위한 전역변수를 할때마다 초기화한다. rightdepth=0; leftnumnode=0; rightnumnode=0; } }
Node * insertTree(Node * a, int data){ if (a == NULL){ a = malloc(sizeof(Node)); a->data = data; a->left = NULL; a->right = NULL; } else { if (data < a->data){ a->left = insertTree(a->left, data); } else { a->right = insertTree(a->right, data); } } return a; }
void binomial_queue<T>::addTreeNotEmpty(tree_reference tree) { if (trees.find(tree) == trees.end()) insertTree(tree); else resolveEqualTrees(*trees.find(tree), tree); }
std::shared_ptr<FunctionTree> CoherentIntensity::createFunctionTree(const ParameterList &DataSample, const std::string &suffix) const { size_t n = DataSample.mDoubleValue(0)->values().size(); auto NodeName = "CoherentIntensity(" + Name + ")" + suffix; auto tr = std::make_shared<FunctionTree>( NodeName, MDouble("", n), std::make_shared<AbsSquare>(ParType::MDOUBLE)); tr->createNode("SumOfAmplitudes", MComplex("", n), std::make_shared<AddAll>(ParType::MCOMPLEX), NodeName); for (auto i : Amplitudes) { std::shared_ptr<ComPWA::FunctionTree> resTree = i->createFunctionTree(DataSample, suffix); if (!resTree->sanityCheck()) throw std::runtime_error("CoherentIntensity::createFunctionTree(): tree " "didn't pass sanity check!"); resTree->parameter(); tr->insertTree(resTree, "SumOfAmplitudes"); } return tr; }
std::shared_ptr<ComPWA::FunctionTree> FormFactorDecorator::createFunctionTree(const ParameterList &DataSample, unsigned int pos, const std::string &suffix) const { // size_t sampleSize = DataSample.mDoubleValue(pos)->values().size(); size_t sampleSize = DataSample.mDoubleValue(0)->values().size(); std::string NodeName = "BreitWignerWithProductionFormFactor(" + Name + ")" + suffix; auto tr = std::make_shared<FunctionTree>(NodeName, MComplex("", sampleSize), std::make_shared<MultAll>(ParType::MCOMPLEX)); std::string ffNodeName = "ProductionFormFactor(" + Name + ")" + suffix; auto ffTree = std::make_shared<FunctionTree>(ffNodeName, MDouble("", sampleSize), std::make_shared<FormFactorStrategy>()); // add L and FFType as double value leaf, since there is no int leaf ffTree->createLeaf("OrbitalAngularMomentum", (double ) L, ffNodeName); ffTree->createLeaf("MesonRadius", MesonRadius, ffNodeName); ffTree->createLeaf("FormFactorType", (double) FFType, ffNodeName); ffTree->createLeaf("MassA", Daughter1Mass, ffNodeName); ffTree->createLeaf("MassB", Daughter2Mass, ffNodeName); ffTree->createLeaf("Data_mSq[" + std::to_string(pos) + "]", DataSample.mDoubleValue(pos), ffNodeName); ffTree->parameter(); tr->insertTree(ffTree, NodeName); std::shared_ptr<ComPWA::FunctionTree> breitWignerTree = UndecoratedBreitWigner->createFunctionTree(DataSample, pos, suffix); breitWignerTree->parameter(); tr->insertTree(breitWignerTree, NodeName); if (!tr->sanityCheck()) throw std::runtime_error( "FormFactorDecorator::createFunctionTree() | " "Tree didn't pass sanity check!"); return tr; };
void sort() { int i; for(i = 0; i < n; i++) { insertTree( v[ i ] ); } inorder( root ); }
int main(){ Node * raiz = novoNode(1); raiz = insertTree(raiz, 2); raiz = insertTree(raiz, 3); /* Node * raiz = novoNode(4); raiz = insertTree(raiz, 2); raiz = insertTree(raiz, 6); raiz = insertTree(raiz, 1); raiz = insertTree(raiz, 3); raiz = insertTree(raiz, 5); raiz = insertTree(raiz, 7); raiz = insertTree(raiz, 8); raiz = insertTree(raiz, 10); raiz = insertTree(raiz, 9); */ /* Node * raiz = novoNode(2); raiz = insertTree(raiz, 1); raiz = insertTree(raiz, 3); */ imprimeArv(raiz); printf("\n"); //raiz = removeOcorrencias(raiz, 2); //imprimeArv(raiz); //printf("\n"); //printf("Maiores: %d\n", elementosMaioresQue(raiz, 1)); printf("Altura: %d\n", alturaDeArvore(raiz)); return 0; }
void constructTree(NODE *temp1,NODE *temp2) { NODE *temp; temp = getNode(); temp->root->left=temp1->root; temp->root->right=temp2->root; temp->root->prob = temp1->root->prob + temp2->root->prob; insertTree(temp); }
BOOL insertTree (TNODE_p_t *root, int data) { if (*root == NULL) { *root = initNode(data); return YES; } TNODE_p_t groot = *root; int choice; printf("\n\tCurrent '%d' | 1. Left%s; 2. Right%s | Choice: ", groot->data, ((groot->left == NULL)?"(*)":""), ((groot->right == NULL)?"(*)":"")); scanf(" %d", &choice); if (choice == 1) return insertTree(&groot->left, data); else if (choice == 2) return insertTree(&groot->right, data); else return NO; return YES; }
int main(){ /* Node * raiz = novoNode(4); raiz = insertTree(raiz, 2); raiz = insertTree(raiz, 6); raiz = insertTree(raiz, 1); raiz = insertTree(raiz, 3); raiz = insertTree(raiz, 5); raiz = insertTree(raiz, 7); raiz = insertTree(raiz, 8); raiz = insertTree(raiz, 10); raiz = insertTree(raiz, 9); */ Node * raiz = novoNode(2); raiz = insertTree(raiz, 1); raiz = insertTree(raiz, 3); raiz = insertTree(raiz, 8); raiz = insertTree(raiz, 10); raiz = insertTree(raiz, 9); imprimeArv(raiz); printf("\n"); Node * achar = searchInOrder(raiz, 1); printf("%d\n", achar->data); raiz = removeNode(raiz, 10); imprimeArv(raiz); printf("\n"); return 0; }
/*! \internal */ void QNodePrivate::insertTree(QNode *treeRoot, int depth) { if (m_scene != nullptr) { treeRoot->d_func()->setScene(m_scene); m_scene->addObservable(treeRoot); } for (QObject *c : treeRoot->children()) { QNode *n = nullptr; if ((n = qobject_cast<QNode *>(c)) != nullptr) insertTree(n, depth + 1); } if (depth == 0) treeRoot->setParent(q_func()); }
void sort() { int i, elem; freopen(FIN, "r", stdin); freopen(FOUT, "w", stdout); scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d", &elem), insertTree(&root, elem ); inorder( root ); fclose( stdin ); fclose( stdout ); }
/* ===== process ===== This function presents the user with the menu. Pre hash, list, tree Post nothing */ void process (HASH *hash, D_LIST *list, BST_TREE *tree) { // Local Definitions char choice; CAR car; // Statements do { choice = getChoice (); switch (choice) { case 'P': printHash(hash); printLinkedList(list); printManager(tree); break; case 'R': printIndentedBST(tree); break; case 'E': printData(hash); break; case 'S': searchByHash(hash, list); break; case 'T': searchByDList(list); break; case 'I': car = addNewNode(); insert(hash,car); insertDNode(list, car); insertTree(tree,car); break; case 'D': deleteCar(list, hash, tree); break; case 'W': writeToFile(list); break; case 'Q': break; } // switch } while (choice != 'Q'); return; } // process
Tree insertLeft(Tree t, TreeEntry e, int *cresceu) { t -> left = insertTree(t -> left, e, cresceu); if(*cresceu) { switch(t -> bf) { case RH: t -> bf = EH; *cresceu = 0; break; case EH: t -> bf = LH; *cresceu = 1; break; case LH: t = balanceLeft(t); *cresceu = 0; } } return t; }
std::shared_ptr<ComPWA::FunctionTree> MCIntegrationStrategy::createFunctionTree( std::shared_ptr<const ComPWA::Intensity> intensity, const std::string &suffix) const { const ParameterList &PhspDataSampleList = PhspSample->getParameterList(); double PhspWeightSum(PhspDataSampleList.mDoubleValue(0)->values().size()); std::shared_ptr<Value<std::vector<double>>> phspweights; try { phspweights = findMDoubleValue("Weight", PhspDataSampleList); PhspWeightSum = std::accumulate(phspweights->values().begin(), phspweights->values().end(), 0.0); } catch (const Exception &e) { } auto tr = std::make_shared<FunctionTree>( "Normalization", ComPWA::ValueFactory(ParType::DOUBLE), std::shared_ptr<Strategy>(new Inverse(ParType::DOUBLE))); tr->createNode("Integral", std::shared_ptr<Strategy>(new MultAll(ParType::DOUBLE)), "Normalization"); // normTree->createLeaf("PhspVolume", PhspVolume, "Integral"); tr->createLeaf("InverseSampleWeights", 1.0 / PhspWeightSum, "Integral"); tr->createNode("Sum", std::shared_ptr<Strategy>(new AddAll(ParType::DOUBLE)), "Integral"); tr->createNode("WeightedIntensities", std::shared_ptr<Strategy>(new MultAll(ParType::MDOUBLE)), "Sum"); if (phspweights) tr->createLeaf("EventWeight", phspweights, "WeightedIntensities"); tr->insertTree(intensity->createFunctionTree(PhspDataSampleList, suffix), "WeightedIntensities"); return tr; }
Tree *q_parse(char *query_text, char **column_names, char *column_type, int num_columns) { if(strstr(query_text,"=") == NULL && strstr(query_text,">") == NULL && strstr(query_text,"<") == NULL) return NULL; if(strstr(query_text, "==") != NULL) return NULL; if(strstr(query_text, "=<") != NULL) return NULL; if(strstr(query_text, "=>") != NULL) return NULL; if(strstr(query_text, "<<") != NULL) return NULL; if(strstr(query_text, ">>") != NULL) return NULL; if(strstr(query_text, "< ") != NULL) return NULL; if(strstr(query_text, " <") != NULL) return NULL; if(strstr(query_text, "> ") != NULL) return NULL; if(strstr(query_text, " >") != NULL) return NULL; if(strstr(query_text, "<>") != NULL) return NULL; if(strstr(query_text, "><") != NULL) return NULL; if(strstr(query_text, "= ") != NULL) return NULL; if(strstr(query_text, " =") != NULL) return NULL; for(int i = 0; i < strlen(query_text); i++) { if(*(query_text+i) == '>' || *(query_text+i) == '<' || *(query_text+i) == '=') { if(i == 0 || i == strlen(query_text) - 1) return NULL; if(*(query_text+i-1) == '=' || *(query_text+i-1) == ' ') return NULL; if(*(query_text+i+1) == ' ' || *(query_text+i+1) == '>' || *(query_text+i+1) == '<') return NULL; } if(*(query_text+i) == '|') { if(i == 0 || i == strlen(query_text) - 1) return NULL; if((*(query_text+i+1) != '|' && *(query_text+i-1) != '|') || (*(query_text+i+1) == '|' && *(query_text+i-1) == '|')) return NULL; } if(*(query_text+i) == '&') { if(i == 0 || i == strlen(query_text) - 1) return NULL; if((*(query_text+i+1) != '&' && *(query_text+i-1) != '&') || (*(query_text+i+1) == '&' && *(query_text+i-1) == '&')) return NULL; } } for(int i = 0; i < strlen(query_text); i++) { if(*(query_text+i) == '>' || *(query_text+i) == '<' || *(query_text+i) == '=') break; if(i == strlen(query_text)) return NULL; } int l = 0; char *tempComp = (char*) malloc(sizeof(char)*strlen(query_text)); for(int i = 0; i < strlen(query_text); i++) { if(*(query_text+i) != ' ') { *(tempComp+l) = *(query_text+i); l++; } } if(*tempComp == '|' || *tempComp == '=' || *tempComp == '>' || *tempComp == '<' || *tempComp == '&') return NULL; if(*(tempComp+l-1) == '|' || *(tempComp+l-1) == '=' || *(tempComp+l-1) == '>' || *(tempComp+l-1) == '<' || *(tempComp+l-1) == '&') return NULL; free(tempComp); int count = 0; for(int i = 0; i < strlen(query_text); i++) { if(*(query_text+i) == '&') { if(*(query_text+i+1) == '&') count++; } else if(*(query_text+i) == '|') { if(*(query_text+i+1) == '|') count++; } } column_n = column_names; column_t = column_type; columnNum = num_columns; return insertTree(query_text, 0, strlen(query_text), count, column_names, column_type, num_columns); }
int main (int argc, const char * argv []) { // Sample input: 1 2 4 8 12 0 15 0 0 0 0 5 0 9 0 0 3 6 10 0 13 16 0 0 17 0 0 11 0 14 18 0 0 19 0 0 7 0 0 // Sample input: 1 2 4 7 0 0 8 10 13 0 0 14 0 0 0 5 0 9 11 0 0 12 0 15 0 0 3 0 6 0 0 TNODE_p_t tree = buildTree(); int choice = 0; do { printf("\n-----------------------------------------------------------------------"); printf("\n\t1. Rebuild tree.\n\t2. Insert element.\n\t3. Preorder traversal.\n\t4. Inorder traversal.\n\t5. Postorder traversal.\n\t6. Search for an element.\n\t7. Path between two elements.\n\t8. Lowest common ancestor.\n\t9. Find diameter of the tree.\n\tChoice: "); scanf(" %d", &choice); if (choice == 1) tree = buildTree(); else if (choice == 2) { int item; printf("\n\tEnter item to be inserted: "); scanf(" %d", &item); insertTree(&tree, item); } else if (choice == 3) preorderRecursive(tree); else if (choice == 4) inorderRecursive(tree); else if (choice == 5) postorderRecursive(tree); else if (choice == 6) { int item; printf("\n\tEnter item to be searched: "); scanf(" %d", &item); TNODE_p_t search = searchTree(tree, item); if (search != NULL) printf("\n\t'%d' is present in the tree. (%p).", item, search); else printf("\n\t'%d' is not present in the tree.", item); } else if (choice == 7) { int itema, itemb; printf("\n\tEnter elements you want to find the path between: "); scanf(" %d", &itema); scanf(" %d", &itemb); TNODE_p_t searcha = searchTree(tree, itema); TNODE_p_t searchb = searchTree(tree, itemb); if (searcha == NULL) printf("\n\t'%d' is not present in the tree.", itema); if (searchb == NULL) printf("\n\t'%d' is not present in the tree.", itemb); if (searcha != NULL && searchb != NULL) { TSNODE_p_t patha = NULL; TSNODE_p_t pathb = NULL; pathFromNode(tree, itema, &patha); pathFromNode(tree, itemb, &pathb); TNODE_p_t lca = lowestCommonAncestor(patha, pathb); TSNODE_p_t pathAB = pathBetweenLists(patha, pathb, lca); printf("\n\tPath between %d and %d: ", itema, itemb); displayList(pathAB); } } else if (choice == 8) { int itema, itemb; printf("\n\tEnter elements you want to find the lowest common ancestor of: "); scanf(" %d", &itema); scanf(" %d", &itemb); TNODE_p_t searcha = searchTree(tree, itema); TNODE_p_t searchb = searchTree(tree, itemb); if (searcha == NULL) printf("\n\t'%d' is not present in the tree.", itema); if (searchb == NULL) printf("\n\t'%d' is not present in the tree.", itemb); if (searcha != NULL && searchb != NULL) { TSNODE_p_t patha = NULL; TSNODE_p_t pathb = NULL; pathFromNode(tree, itema, &patha); pathFromNode(tree, itemb, &pathb); TNODE_p_t lca = lowestCommonAncestor(patha, pathb); printf("\n\tLowest common ancestor of %d and %d: %d", itema, itemb, lca->data); } } else if (choice == 9) { int diam = diameter(tree); printf("\n\tDiameter of the tree = %d.", diam); } } while (choice >= 1 && choice <= 9); printf("\n\n"); return 0; }
void test_insert_root_node(){ Tree tree = createTree(compareInteger); int data = 1; int result = insertTree(&tree, NULL, &data); ASSERT(1 == result); }
void ItemExprList::insertTree(ItemExpr *tree, OperatorTypeEnum backBoneType, NABoolean flattenSBQ, NABoolean flattenUDF) { if (tree->getOperatorType() == backBoneType) { for (Int32 i = 0; i < tree->getArity(); i++) { // Check for NULL list for right linear trees. That is, arity may be // two, but second child is NULL. ItemExpr *child = tree->child(i); if (child) insertTree(tree->child(i), backBoneType, flattenSBQ, flattenUDF); } } else if (tree->getOperatorType() == ITM_ONE_ROW) { Aggregate *agr = (Aggregate *)tree; if (agr->isOneRowTransformed_) { for (Int32 i = 0; i < tree->getArity(); i++) insertTree(tree->child(i), backBoneType, flattenSBQ, flattenUDF); } else { // do nothing, postpone this processing until OneRow transformation // is done } } else if ((flattenSBQ AND tree->isASubquery()) OR (flattenUDF AND (tree->getOperatorType() == ITM_USER_DEF_FUNCTION)) AND (NOT tree->nodeIsTransformed())) // Added the extra check for transformation above to avoid any issues // where we might flatten a subquery/MVF a second time around while // we deal with ValueIdProxies. // The ValueIdProxy->needToTransformChild() // flag should be sufficient, but it never hurts to be safe. { ValueIdList cols; NABoolean haveRDesc(FALSE); if (tree->isASubquery()) { // flatten the subquery select list RETDesc *retDesc = ((Subquery*)tree)->getSubquery()->getRETDesc(); if (retDesc) { retDesc->getColumnList()->getValueIdList(cols); if (cols.entries() > 1) { haveRDesc = TRUE; } } } else if (tree->getOperatorType() == ITM_USER_DEF_FUNCTION) { // flatten the UDF by adding the additional outputs to the tree const RoutineDesc *rDesc = ((UDFunction *)tree)->getRoutineDesc(); if (rDesc && rDesc->getOutputColumnList().entries() > 1) { cols = rDesc->getOutputColumnList(); haveRDesc = TRUE; } } if (haveRDesc == TRUE) { for (CollIndex i = 0; i < cols.entries(); i++) { ValueId proxyId; proxyId = cols[i]; // We create a ValueIdProxy for each element in the subquery's // select list or for each output parameter of a MVF. The first // one of these will be marked to be transformed. This allows // us to get the correct degree of statements containing MVFs or // subquery with degree > 1 at bind time. ValueIdProxy *proxyOutput = new (CmpCommon::statementHeap()) ValueIdProxy( tree->getValueId(), proxyId, i); proxyOutput->synthTypeAndValueId(); // Make sure we transform the subquery or MVF if (i == 0 ) proxyOutput->setTransformChild(TRUE); insert(proxyOutput); } } else insert(tree); // we are processing a valueId of a UDFunction // or subquery before we have bound it. Just insert // its valueId and we'll have to deal with it later.. } else insert(tree); }
void BinarySearchTree<T>::insertTree(T item) { insertTree(item,root); }
/*implements A* algorithm*/ tree astar(int x, int y, int d, int heuristic){ char a = 'X';//X simbolize that no action was taken to get there tree t, t1, t2; char **mat1, **mat2; int i, j; int level; double f; queue_vector aux; int k; //copy the starting matrix mat1 = newMatrix(); for(i = 0; i < n; i++){ for(j = 0; j < m; j++) mat1[i][j] = w[i][j]; } t1 = insertTree(NULL, d, x, y, mat1, a, 0); t = t1; //compute the f value according to the heuristic f = computeHeuristic(x, y, 0, heuristic); insertQueue(t1, f); while(n_queue > 0){ //remove the first element of the queue removeQueue(&aux.t, &aux.f); t1 = aux.t; d = t1 -> dirt; mat1 = t1 -> mat; a = t1 -> action; x = t1 -> x; y = t1 -> y; level = t1 -> level; //increments the number of nodes expanded expanded++; //adds into the queue if(y != 0 && mat1[y-1][x] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y-1][x]; mat2[y-1][x] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x, y-1), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x, y-1); t2 = insertTree(t1, d-1, x, y-1, mat2, 'n', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x, y-1, mat2, 'N', level + 1); t1 -> N = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(y != n - 1 && mat1[y+1][x] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y+1][x]; mat2[y+1][x] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x, y+1), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x, y+1); t2 = insertTree(t1, d-1, x, y+1, mat2, 's', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x, y+1, mat2, 'S', level + 1); t1 -> S = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(x != 0 && mat1[y][x-1] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y][x-1]; mat2[y][x-1] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x - 1, y), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x-1, y); t2 = insertTree(t1, d-1, x-1, y, mat2, 'w', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x-1, y, mat2, 'W', level + 1); t1 -> W = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } if(x != m - 1 && mat1[y][x+1] != '#'){ mat2 = newMatrix(); copyMatrix(mat1, mat2); a = mat1[y][x+1]; mat2[y][x+1] = '@'; mat2[y][x] = '_'; if(a == '*') k = d-1; else k = d; if(checkDuplicate(t, mat2, hashFunction(x + 1, y), k) == 0){ //inserts in lowercase if there is dirt if(a == '*'){ removeListDirt(x+1, y); t2 = insertTree(t1, d-1, x+1, y, mat2, 'e', level + 1); if(d-1 == 0) return t2; } else t2 = insertTree(t1, d, x+1, y, mat2, 'E', level + 1); t1 -> E = t2; //compute the f value according to the heuristic f = computeHeuristic(x, y-1, level+1, heuristic); insertQueue(t2, f); generated++; } } orderQueue(); } return NULL; }