All pastes #297069 Raw Edit

Miscellany

public text v1 · immutable
#297069 ·published 2006-12-30 20:42 UTC
rendered paste body
     1  #include <stdio.h>
     2  #include <stdlib.h>
     3  #include <string.h>
     4  typedef struct arv{
     5      int chave;
     6      struct arv *esq, *dir, *pai;
     7  }Tarv;
     8  Tarv *cn(){
     9      Tarv *p;
    10      p=(Tarv *)malloc(sizeof(Tarv));
    11      p->esq=NULL;
    12      p->dir=NULL;
    13      return p;
    14  }
    15  Tarv *ca(int x){
    16      Tarv *p;
    17      p=cn();
    18      p->chave=x;
    19      return p;
    20  }
    21  int *ins(int x,Tarv *p){
    22      Tarv *q;
    23      q=ca(x);
    24      if(x<p->chave){
    25          if (p->esq){
    26              printf("Nao foi possivel fazer a insersao");
    27          }
    28          else{
    29              p->esq=q;
    30          }
    31      }
    32      else{
    33          if (x>p->chave){
    34              if(p->dir){
    35                  printf("Nao foi possivel fazer a insersao");
    36              }
    37              else{
    38                  p->dir=q;
    39              }
    40          }
    41          else{
    42              printf("O valor que voce colocou eh igual ao valor da raiz, vtnc");
    43          }
    44      }
    45  }
    46  int acha(Tarv *p,int x){
    47      Tarv *z;
    48      int t;
    49      while(p->chave!=NULL){
    50          if (p->chave==x){
    51              printf("Esse numero existe na arvore!");
    52          }
    53          else{
    54              if(p->chave>x){
    55                  p=p->esq;
    56              }
    57              else{
    58                  p=p->dir;
    59              }
    60          }int acha(Tarv *p,int x){
    61      Tarv *z;
    62      int t;
    63      while(p->chave!=NULL){
    64          if (p->chave==x){
    65              printf("Esse numero existe na arvore!");
    66          }
    67          else{
    68              if(p->chave>x){
    69                  p=p->esq;
    70              }
    71              else{
    72                  p=p->dir;
    73              }
    74          }
    75  }
    76  int main(){
    77      Tarv *p;
    78      int a=2,b=3,c=4;
    79  }