コード例 #1
0
ファイル: jansen.c プロジェクト: karinaawoki/jansen_arvores
/* M = M+1 */
int main (int argc, char *argv[])
{
    int m, *bResult, *wResult;
    int root = 0;
    Graph *G;
    
    m = atoi(argv[2]);
    G = read(argv[1]);
    tempoInicial = clock();

    
    bResult = malloc((m+1)*sizeof(int));
    wResult = malloc((m+1)*sizeof(int));


    recursao(G, root, 0, m+1, bResult, wResult);

    tempoFinal = clock();

    if(DEBUG)printVector(bResult, m+1);
    if(DEBUG)printVector(wResult, m+1);
    printf("%d\n", menor(bResult[m], wResult[m]));
    freeGraph(G);
    free(bResult);
    free(wResult);

    tempoGasto = (tempoFinal-tempoInicial)*1.0/CLOCKS_PER_SEC;
    printf("TEMPO: %f seg \n", tempoGasto);
    
    return 0;
}
コード例 #2
0
void main ()
{
    const int n=1;

    printf ("Os números até 10 são:\n");

    recursao(n);
}
コード例 #3
0
void recursao (int n)
{
    if (n == 10)
        printf ("%d ", n);

    else{
        recursao(n+1);
        printf ("%d ", n);
    }
}
コード例 #4
0
ファイル: jansen.c プロジェクト: karinaawoki/jansen_arvores
int recursao(Graph *G, int root, int parent, int m, int *bResult, int *wResult)
{
    /* retorna -- */
    int k = 0; /* contador para filhos */
    int i;
    int *bPrime, *wPrime, *bPrimePrime, *wPrimePrime; 
    Vertex *v;
    if(DEBUG) printf("DESCEU %d\n", root);
    v = G->adj[root]->next;
 

    /* quando é folha, retorna valor das folhas */
    if(v == NULL || (v->vertex ==parent && v->next == NULL)) /* LEAFS */
    {
        if(DEBUG) printf(" FOLHA\n");
        bLeaf(m, bResult);
        wLeaf(m, wResult);
        return 0;
    }
    
    
    /* percorre todos os filhos */
    for (; v!=NULL; v = v->next)
    {
        if(parent != v->vertex)
        {
            /* reutilizando bwResult */
            recursao(G, v->vertex, root, m, bResult, wResult);
            bPrime = malloc(m*sizeof(int));
            wPrime = malloc(m*sizeof(int));
            

            if(DEBUG){
                printf("b[%d]:  ", v->vertex);
                printVector(bResult, m);
                printf("w[%d]:  ", v->vertex);
                printVector(wResult, m);
            }
            calculaBprime(m, bResult, wResult, bPrime);
            calculaWprime(m, bResult, wResult, wPrime);

            if(DEBUG){
                printf("b'[%d]:  ", v->vertex);
                printVector(bPrime, m);
                printf("w'[%d]:  ", v->vertex);
                printVector(wPrime, m);
            }

            /* primeiro filho */
            if(k == 0) 
            {
                bPrimePrime = malloc(m*sizeof(int));
                wPrimePrime = malloc(m*sizeof(int));   
            }
            for (i = 0; i < m && k == 0; i++)
            {
                bPrimePrime[i] = bPrime[i];
                wPrimePrime[i] = wPrime[i];
            }

            /* demais filhos */
            if( k>0)
            {
                calculaBprimePrime(m, bPrimePrime, bPrime);
                calculaWprimePrime(m, wPrimePrime, wPrime);
            }

            free(bPrime);
            free(wPrime);

            k++;
            if(DEBUG) printf("---------\n");

        }
    }
    for(i = 0; i<m; i++)
    {
        bResult[i] = bPrimePrime[i];
        wResult[i] = wPrimePrime[i];
    }
    free(bPrimePrime);
    free(wPrimePrime);
    return 0;
}