Advertisement
Gabriel_Rofl

arvore.c

Nov 7th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "arvore.h"
  4.  
  5. t_no* aloca_no(int valor){
  6.     t_no* ptr = (t_no *) malloc(sizeof(t_no));
  7.     ptr->dado = valor;
  8.     ptr->direita = NULL;
  9.     ptr->esquerda = NULL;
  10.     return ptr;
  11. }
  12.  
  13.  
  14. t_tree* first(){
  15.     t_tree* ptr = (t_tree *) malloc(sizeof(t_tree));
  16.     ptr->inicio = NULL;
  17.     return ptr;
  18. }
  19.  
  20. int type(){
  21.     int num;
  22.     printf("Informe o tipo de busca da arvore binaria: ");
  23.     printf("1- pre-ordem\n");
  24.     printf("2- em ordem\n");
  25.     printf("3- pos-ordem\n");
  26.     scanf("%d", &num);
  27.     return num;
  28. }
  29.  
  30.  
  31. void insere(t_no* node, t_tree* raiz){
  32.     int value, check_raiz = 1;
  33.     while(check_raiz == 1/*Ajustar essa condicao*/){
  34.         if(raiz->inicio == NULL){
  35.             printf("Valor do começo: ");
  36.             scanf("%d", &value);
  37.             node = aloca_no(value);
  38.             raiz->inicio = node;
  39.             insere(node, raiz);
  40.         }
  41.         else{
  42.             if(node->esquerda == NULL){
  43.                 printf("Valor do no: ");
  44.                 scanf("%d", &value);
  45.                 node->esquerda = aloca_no(value);
  46.                 insere(node, raiz);
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement