예제 #1
0
int verificaLivelli(albero a1,albero a2,int v) {
    listaInteri l1 = allocaLista(a1, v);
    listaInteri l2 = allocaLista(a2, v);
    int result=0;
    while(l2!=NULL) {
        if(contain(l1,l2->info)) {
            result++;
        }
        l2=l2->next;
    }
    return result;
}
예제 #2
0
void modificaFile(albero t) {
    FILE *f;
    int x=0;
    int y=0;
    long pos=0;
    f=fopen("/Users/marcofaretra/Desktop/livello.txt", "r+");
    if(f==NULL) printf("Errore connessione");
    else {
        while(fscanf(f, "%d %d\n",&x,&y)!=EOF) {
            if(y!=lungLista(allocaLista(t, x))) {
                fseek(f, pos, SEEK_SET);
                fprintf(f, "%d %d\n",x,lungLista(allocaLista(t, x)));
            }
            pos=ftell(f);
        }
    }
}
int verificaLivelli(albero t1, albero t2, int v) {
    int cont = 0;
    lista t1l = allocaLista(t1, v);
    lista t2l = allocaLista(t2, v);
    lista i1 = t1l;
    lista i2 = t2l;
    if (t1l == NULL && t2l == NULL)
        return 0;
    else {
        while (i1 != NULL) {
            while (i2 != NULL) {
                if (i1->info == i2->info)
                    cont++;
                i2 = i2->next;
            }
            i2 = t2l;
            i1 = i1->next;
        }
    }
    return cont;
}
int main(int argc, const char * argv[]) {
    albero s = malloc(sizeof(nodoAlbero));
    s->info = 'k';
    
    s->left = malloc(sizeof(nodoAlbero));
    s->left->info = 'e';
    
    s->right = malloc(sizeof(nodoAlbero));
    s->right->info = 'm';
    
    s->left->left = malloc(sizeof(nodoAlbero));
    s->left->left->info = 'b';
    
    s->left->right = malloc(sizeof(nodoAlbero));
    s->left->right->info = 'f';
    s->left->right->left=NULL;
    s->left->right->right=NULL;
    
    s->left->left->left = malloc(sizeof(nodoAlbero));
    s->left->left->left->info = 'a';
    s->left->left->left->left = NULL;
    s->left->left->left->right = NULL;
    
    s->left->left->right = malloc(sizeof(nodoAlbero));
    s->left->left->right->info = 'c';
    s->left->left->right->left = NULL;
    s->left->left->right->right = NULL;
    
    s->right->left = malloc(sizeof(nodoAlbero));
    s->right->left->info = 'l';
    s->right->left->left = NULL;
    s->right->left->right = NULL;
    
    s->right->right = malloc(sizeof(nodoAlbero));
    s->right->right->info = 's';
    s->right->right->left = NULL;
    s->right->right->right = NULL;
    
    printf("%d\n", distanza(s, 'k', 'z'));
    lista l = allocaLista(s, 'k');
    stampaLista(l);
    free(l);
    free(s);
    return (0);
}