// IED-001 (Prof. Dr. Silvio do Lago Pereira) // ----------------------------------------------------------------------------- // Exemplo 1 // ----------------------------------------------------------------------------- typedef int Item; typedef struct arv { struct arv *esq; Item item; struct arv *dir; } *Arv; // ----------------------------------------------------------------------------- // Exemplo 2 // ----------------------------------------------------------------------------- Arv arv(Arv e, Item x, Arv d) { Arv n = malloc(sizeof(struct arv)); n->esq = e; n->item = x; n->dir = d; return n; } // ----------------------------------------------------------------------------- // Exemplo 4 // ----------------------------------------------------------------------------- void exibe(Arv A,int n) { if( A==NULL ) return; exibe(A->dir,n+1); printf("%*s%d\n",3*n,"",A->item); exibe(A->esq,n+1); } // ----------------------------------------------------------------------------- // Exercicio 1 // ----------------------------------------------------------------------------- #include #include ... int main(void) { Arv I = arv(arv(NULL,2,NULL),1,arv(NULL,3,arv(NULL,4,NULL))); exibe(I,0); return 0; } // ----------------------------------------------------------------------------- // Exemplo 5 // ----------------------------------------------------------------------------- Arv completa(int h) { if( h==0 ) return NULL; return arv(completa(h-1), rand()%100, completa(h-1)); } // ----------------------------------------------------------------------------- // Exercicio 4 // ----------------------------------------------------------------------------- int main(void) { srand(time(NULL)); exibe(balanceada(9),0); return 0; } // ----------------------------------------------------------------------------- // Exercicio 5 // ----------------------------------------------------------------------------- int main(void) { srand(time(NULL)); exibe(aleatoria(9),0); return 0; }