int main(){ arvore* a = criaArvore(); adicionaElem(&(a->raiz), 10, a); adicionaElem(&(a->raiz), 3, a); adicionaElem(&(a->raiz), 8, a); adicionaElem(&(a->raiz), 5, a); adicionaElem(&(a->raiz), 6, a); adicionaElem(&(a->raiz), 4, a); adicionaElem(&(a->raiz), 9, a); adicionaElem(&(a->raiz), 2, a); adicionaElem(&(a->raiz), 1, a); adicionaElem(&(a->raiz), 11, a); imprimeArv(a->raiz); printf("-----------------------\n"); noAvo = NULL; noPai = NULL; removeElem(&(a->raiz), 8, a); printf("Raiz: %d\n", a->raiz->elem); imprimeArv(a->raiz); printf("-----------------------\n"); return 0; }
// Delete an element from the // queue and clean up. void Queue::on_pushButton_clicked() { QString val; QRect rect; QFont font; std::map <int, Ui::RectElement>::iterator it, it2; if (!qList->getNumEntries()) { return; } // Remove the first element removeElem(0); }
void EEMS::propose_birthdeath_qVoronoi(Proposal &proposal) { int newqtiles = nowqtiles,r; double u = draw.runif(); double pBirth = 0.5; double pDeath = 0.5; boost::math::normal pnorm(0.0,sqrt(nowqrateS2)); proposal.newqEffcts = nowqEffcts; proposal.newqSeeds = nowqSeeds; // If there is exactly one tile, rule out a death proposal if ((nowqtiles==1) || (u<0.5)) { // Propose birth if (nowqtiles==1) { pBirth = 1.0; } newqtiles++; MatrixXd newqSeed = MatrixXd::Zero(1,2); randpoint_in_habitat(newqSeed); pairwise_distance(nowqSeeds,newqSeed).col(0).minCoeff(&r); // The new tile is assigned a rate by perturbing the current rate at the new seed double nowqEffct = nowqEffcts(r); double newqEffct = draw.rtrnorm(nowqEffct,params.qEffctProposalS2,params.qEffctHalfInterval); insertRow(proposal.newqSeeds,newqSeed.row(0)); insertElem(proposal.newqEffcts,newqEffct); // Compute log(proposal ratio) and log(prior ratio) proposal.newratioln = log(pDeath/pBirth) - dtrnormln(newqEffct,nowqEffct,params.qEffctProposalS2,params.qEffctHalfInterval) - log(cdf(pnorm,params.qEffctHalfInterval) - cdf(pnorm,-params.qEffctHalfInterval)); proposal.newpi = nowpi + log((nowqtiles+params.negBiSize)/(newqtiles/params.negBiProb)) - 0.5 * log(nowqrateS2) - 0.5 * newqEffct*newqEffct/nowqrateS2; } else { // Propose death if (nowqtiles==2) { pBirth = 1.0; } newqtiles--; int qtileToRemove = draw.runif_int(0,newqtiles); MatrixXd oldqSeed = nowqSeeds.row(qtileToRemove); removeRow(proposal.newqSeeds,qtileToRemove); removeElem(proposal.newqEffcts,qtileToRemove); pairwise_distance(proposal.newqSeeds,oldqSeed).col(0).minCoeff(&r); double nowqEffct = proposal.newqEffcts(r); double oldqEffct = nowqEffcts(qtileToRemove); // Compute log(prior ratio) and log(proposal ratio) proposal.newratioln = log(pBirth/pDeath) + dtrnormln(oldqEffct,nowqEffct,params.qEffctProposalS2,params.qEffctHalfInterval) + log(cdf(pnorm,params.qEffctHalfInterval) - cdf(pnorm,-params.qEffctHalfInterval)); proposal.newpi = nowpi + log((nowqtiles/params.negBiProb)/(newqtiles+params.negBiSize)) + 0.5 * log(nowqrateS2) + 0.5 * oldqEffct*oldqEffct/nowqrateS2; } proposal.move = Q_VORONOI_BIRTH_DEATH; proposal.newqtiles = newqtiles; proposal.newll = eval_birthdeath_qVoronoi(proposal); }
int validSuccessor(tQueue *a, tQueue *f, tNodeQueue *p, tNodeQueue *m, int heuristica) { m->elem->g = p->elem->g + 1; printf("%d\n",a); if ((!(memberOf(m, a)) || (!(memberOf(m, f))))) { insertAtEnd(m, a); calcH(p, m, heuristica); } else { if (memberOfWithGMin(m, a)) { insertAtEnd(m, a); calcH(p, m, heuristica); } else { if (memberOfWithGMin(m, f)) { removeElem(m, f); insertAtEnd(m, a); calcH(p, m, heuristica); } } } }
int main() { int i; List *l = NULL; List *(* listAddFunc)(List *, void *) = append; #ifdef DEMO_PREPEND listAddFunc = prepend; #endif for (i=0; i < 40; ++i) { int *tp = (int *)malloc(sizeof(int)); *tp = i; l = listAddFunc(l, tp); } #ifdef DEMO_CIRCULARITY while (l->head != NULL) { void *vSav = listPop(&(l->head)); if (vSav != NULL) { printf("vS: %d\n", *(int *)vSav); free(vSav); } break; } #endif printList(l); printf("\n"); i = 8; printf("Size: %d\n", getListSize(l)); l = removeElem(l, &i, intPtrComp); printf("Size: %d\n", getListSize(l)); printList(l); printf("\n"); destroyList(l); return 0; }
unsigned long long* getPermutations(int n, int* arr) { int i; int j; int idx = 0; unsigned long long* perms; unsigned long long* c = malloc(sizeof(unsigned long long) * fact(n)); if (n > 2) // divide { for (i = 0; i < n; i++) { // remove element i from array // recurse w/ shortened arrays perms = getPermutations(n-1, removeElem(arr, arr[i], n)); //printf("%i: %i\n", i, n); // iterate through shortened arrays, appending i to the front of each for (j = 0; j < fact(n-1); j++) { c[idx] = joinIntInt(arr[i], perms[j], n); //printf("%i\n", c[idx]); idx++; } } // return c return c; } else // conquer { // arr[0], arr[1] // arr[1], arr[0] c[0] = joinIntInt(arr[0], arr[1], 2); c[1] = joinIntInt(arr[1], arr[0], 2); return c; } }
void eliminarProduccionesLambda(gramatica_t g) { int cant = 0, i = 0, j = 0; char auxNT; for (i = 0; g->producciones[i] != NULL; i++) { cant++; } for (i = 0; i < cant; i++) { if (g->producciones[i]->parteDerecha[0] == '-') { auxNT = g->producciones[i]->parteIzquierda; for (j = 0; j < cant; j++) { int qty = 0; if (g->producciones[j]->parteDerecha[0] != '-' && (qty = containsElem(g->producciones[j]->parteDerecha, g->producciones[i]->parteIzquierda))) { while (qty > 0) { char * pD = removeElem(g->producciones[j]->parteDerecha, auxNT, qty--); /*if(strlen(pD)==0){ //pD = malloc(5*sizeof(char)); pD[0]='\\'; pD[1]='\0'; }*/ agregarProduccion(g, pD, g->producciones[j]->parteIzquierda); cant++; } //g->producciones[j]->noTerminal = NULL; } } if (g->producciones[i]->parteIzquierda != g->simInicial) { eliminarProduccion(g, g->producciones[i]); i--; cant--; } } } }
void *onFinish(Heap *h, unsigned int id) { Load similarElem; similarElem.id = id; void *popd = removeElem(h, &similarElem); return popd; }
int main() { // Matriz de adjacencia que representa o grafo int adjacencia[MAX][MAX]; // Fila que armazena os vetores inexplorados No_fila *fila = NULL; // Vetor que armazena o estado de cada vertice, sendo os possiveis valores: // BRANCO se o vertice ainda não foi visitado // CINZA se foi visitado porém não explorado // PRETO se seus adjacentes já foram visitados int cor[MAX]; // Vetor que armazena a distancia de cada vertice até o vertice 0 // Uma distancia de -1 significa que não existe caminho entre os vertices int distancia[MAX]; // Número de autores e de relações de co-autoria, respectivamente int n, m; // Vertice que está sendo explorado int explorando; // Inteiro que armazena a distancia maxima encontrada int max; // Inteiros auxiliares int i, j, x, y; // Recebe o 'n' inicial scanf("%d", &n); // Recebe o 'm' inicial scanf("%d", &m); // Laço principal while (n != 0 || m != 0) { // Reinicia a matriz de adjacencia e os vetores de estado e distancia for (i = 0; i < n; i++) { for (j = 0; j < n; j++) adjacencia[i][j] = 0; cor[i] = BRANCO; distancia[i] = -1; } // Recebe as 'm' relações de co-autoria for (i = 0; i < m; i++) { scanf("%d", &x); scanf("%d", &y); adjacencia[x][y] = 1; adjacencia[y][x] = 1; } // Define o vetor 0 como inexplorado e como 0 de distancia cor[0] = CINZA; distancia[0] = 0; // Insere o vertice 0 na fila de inexplorados fila = insereElem(fila, 0); // Explora os elementos da fila while (fila != NULL) { explorando = fila->valor; for (i = 0; i < n; i++) { if (adjacencia[explorando][i] == 1) { if (cor[i] == BRANCO) { distancia[i] = distancia[explorando] + 1; cor[i] = CINZA; fila = insereElem(fila, i); } } } fila = removeElem(fila); cor[explorando] = PRETO; } // Encontra algum vértice que possui distancia infinita, ou o que // possui maior distancia até o vértice 0 max = 0; for (i = 0; i < n; i++) { if (distancia[i] == -1) { max = -1; break; } else if (distancia[i] > max) max = distancia[i]; } // Imprime o resultado if (max == -1) printf("infinito\n"); else printf("%d\n", max); // Recebe um novo 'n' scanf("%d", &n); // Recebe um novo 'm' scanf("%d", &m); } return 0; }