Ejemplo n.º 1
0
void nodos (struct nodo *r)
{
    struct nodo *aux;

    if (r->i) {
        aux = r->i;
        cont++;
        nivel (aux);
    }
    if (r->d) {
        aux = r->d;
        cont++;
        nivel (aux);
    }
}
Ejemplo n.º 2
0
int main(){

//Testar exo 1
	char s1[10] ="marianas";
	char s2[4] ="ana";

	char* o = strstr(s1, s2);

	printf("%s  %s  %s\n ", s1, s2, o);

//
	//Testar exo2
	int v[4] ={ 90, 4, 80, 2};
	int in = maxInd(v, 4);
	printf("O indice do maior valor no vetor v é %d cujo elemento é %d\n", in, v[in]);

//Testar exo 3
	printf("Antes do concat\n");
	LInt a = (LInt)malloc(sizeof(struct slist));
	a->valor = 10;
	a->prox = (LInt)malloc(sizeof(struct slist));
	a->prox->valor = 20;
	a->prox->prox = NULL;

	printL(a);

	LInt b = (LInt)malloc(sizeof(struct slist));
	b->valor = 30;
	b->prox = (LInt)malloc(sizeof(struct slist));
	b->prox->valor = 40;
	b->prox->prox= NULL;
	printL(b);

	concat3(&a, b);

	printf("Depois do concat\n");

	//a = concat(a,b);
	printL(a);

	//Testar exo4

	printf("Exo 4\n");
	ABin ar = (ABin)malloc(sizeof(struct nodo));
	ar->valor = 50;
	ar->esq = (ABin)malloc(sizeof(struct nodo));
	ar->esq->valor = 30;
		ar->esq->esq = NULL;
		ar->esq->dir=NULL;

	ar->dir = (ABin)malloc(sizeof(struct nodo));
	ar->dir->valor = 80;
		ar->dir->esq = NULL;
		ar->dir->dir = NULL;

	LInt lis = nivel(ar, 2);
	printL(lis);

	return 0;
}
Ejemplo n.º 3
0
void nivel (struct nodo *r)
{
    struct nodo *aux;

    if (r->i) {
        aux = r->i;
        cont++;
        nivel (aux);
    }
    if (r->d) {
        aux = r->d;
        cont++;
        nivel (aux);
    }
    if (cont > mayor)
        mayor = cont;
    cont--;
}
Ejemplo n.º 4
0
/*
 *dada uma arvore binária, constroi uma lista
 *com os valores dos elementos que estao
 *armazenados na arvore ao nivel n.
 * A raiz está ao nivel 1.
 */
LInt nivel(ABin a, int n){
	if(a==NULL)return NULL;
	if(n==1 && a){
		LInt lista = (LInt)malloc(sizeof(struct slist));
		lista->valor = a->valor;
		lista->prox = NULL;
		return lista;
	}

	while(n>1){
		n--;
		LInt * l1 = nivel(a->esq, n);
		LInt l2 = nivel(a->dir, n);
		concat(l1, l2);
		return l1;
	}


}