Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
codigos-lista-arvore/exer1.c typedef struct { int chave; }tipo_elemento; typedef struct nodo{ struct nodo *dir, *esq; tipo_elemento e; }tipo_nodo; typedef tipo_nodo *apontador; int estritamente_bin(apontador a){ if(!a->dir && !a->esq) return 1; if(a->dir && a->esq) return estritamente_bin(a->esq) && estritamente_bin(a->dir); return 0; } codigos-lista-arvore/exer2.c int altura(link h) { int u, v; if (h == NULL) return -1; u = altura(h->l); v = altura(h->r); if (u > v) return u+1; else return v+1; } codigos-lista-arvore/exer3.c #include<stdio.h> #include<stdlib.h> typedef int tdado; typedef struct no{ tdado dado; struct no *dir,*esq; }tno; //--------------------- tno *criaNo(tdado x){ tno *novo; novo = malloc(sizeof(tno)); novo->dado = x; novo->esq = NULL; novo->dir = NULL; return novo; } //------------------------- tno *insere(tno *raiz, tno *novo){ if(raiz==NULL) return novo; if(novo->dado < raiz->dado) raiz->esq = insere(raiz->esq, novo); else raiz->dir = insere(raiz->dir, novo); return raiz; } //-------------------------------- void preOrder(tno *raiz){ if(raiz!=NULL){ printf("%d - ",raiz->dado); preOrder(raiz->esq); preOrder(raiz->dir); } } //-------------------------------- void inOrder(tno *raiz){ if(raiz!=NULL){ inOrder(raiz->esq); printf("%d - ",raiz->dado); inOrder(raiz->dir); } } //----------------------------- void postOrder(tno *raiz){ if(raiz!=NULL){ postOrder(raiz->esq); postOrder(raiz->dir); printf("%d - ",raiz->dado); } } //----------------------------- int menu(){ int op; printf("1-Inserir\n"); printf("2-Percursos em Profundidade\n"); printf("6-Remover Raiz\n"); printf("0-Sair\n"); scanf("%d",&op); return op; } //---------------- int main(){ int op; tno *raiz=NULL; tdado dado; do{ printf("PreOrder:"); preOrder(raiz); printf("\n"); op = menu(); switch(op){ case 1: printf("Dado:"); scanf("%d",&dado); raiz = insere(raiz,criaNo(dado)); printf("Inserido :)\n"); break; case 2: printf("\nPreOrder:"); preOrder(raiz); printf("\nInOrder:"); inOrder(raiz); printf("\nPostOrder:"); postOrder(raiz); break; case 3: printf("Qtde de nos: %d\n",contaNos(raiz)); break; case 0: printf("Saindo...."); break; } getch(); system("cls"); }while(op!=0); } codigos-lista-arvore/exer4.c typedef struct node *link; struct node { int item; link l, r; } ; //letra A int count(link h) { if (h == NULL) return 0; return count(h->l) + count(h->r) + 1; } //letra B int soma(link h) { if(h == null) return 0; else { int soma = 0; soma += soma(h.l); soma += soma(h.r); return soma; } } //letra C //letra D int countnos(link h) { if (h == NULL) return 0; return countnos(h->l) + countnos(h->r) + 1; } codigos-lista-arvore/exer5.c int ident(tno *raiz,tno *n0){ if(raiz!=NULL){ if(no->esq||no->dir != NULL) printf("No interno. \n"); else printf("Folha. \n"); } } codigos-lista-arvore/exer6.c #include<stdio.h> struct graph { int V; int A; link *adj; }; typedef struct graph *Graph; typedef struct node *link; struct node { vertex w; link next; }; static link NEWnode( vertex w, link next) { link a = malloc( sizeof (struct node)); a->w = w; a->next = next; return a; } Graph GRAPHinit( int V) { Graph G = malloc( sizeof *G); G->V = V; G->A = 0; G->adj = malloc( V * sizeof (link)); for (vertex v = 0; v < V; ++v) G->adj[v] = NULL; return G; } void GRAPHinsertArc( Graph G, vertex v, vertex w) { for (link a = G->adj[v]; a != NULL; a = a->next) if (a->w == w) return; G->adj[v] = NEWnode( w, G->adj[v]); G->A++; }
Compartilhar