All pastes #2074480 Raw Edit

O

public c v1 · immutable
#2074480 ·published 2011-06-04 06:44 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>int h=0;typedef struct arvore{        struct arvore *esq;        struct arvore *dir;        int isbn;        char titulo[100];        char autor[100];        int estoque;        int fb;}AVL;AVL *aloca_no(int x);void __insereAVL(AVL **pt, int x);void __caso1__(AVL **pt);void __caso2__(AVL **pt);void __percurso__ordem__AVL(AVL **pt);void __mostrar_Arv_AVL(AVL *pt);void __buscar_Arv_AVL(AVL *pt);AVL *aloca_no(int x){    AVL *novo_no;    novo_no = (AVL*)malloc(sizeof(AVL));    novo_no->fb = 0;    novo_no->isbn = x;    fflush(stdin);    printf("Informe o nome do livro\n");    scanf("%s", novo_no->titulo);    printf("Informe o nome do autor\n");    scanf("%s", novo_no->autor);    printf("Informe a quantidade de livros em estoque\n");    scanf("%i",&novo_no->estoque);    novo_no->esq = NULL;    novo_no->dir = NULL;    return novo_no;   }void __insereAVL(AVL **pt, int x){     if(*pt == NULL){           *pt = aloca_no(x);            h = 1;     }else{           if(x == (*pt)->isbn){                printf("Isbn existente.\n");           }           if(x < (*pt)->isbn ){                __insereAVL(&(*pt)->esq,x);                if(h == 1 ){                   switch((*pt)->fb){                       case -1:                            (*pt)->fb = 0;                             h = 0;                             break;                       case 0:                             (*pt)->fb = 1;                             break;                       case 1:                             __caso1__(&(*pt));                             break;                   }                 }           }          if(x > (*pt)->isbn){              __insereAVL(&(*pt)->dir,x);               if(h == 1){                   switch((*pt)->fb){                       case 1:                          (*pt)->fb = 0;                           h = 0;                           break;                       case 0:                           (*pt)->fb = -1;                            break;                       case -1:                            __caso2__(&(*pt));                            break;                   }              }          }     }}void __caso1__(AVL **pt){     AVL *ptu,*ptv;           ptu = (*pt)->esq;           if(ptu->fb == 1){                (*pt)->esq = ptu->dir;                ptu->dir = (*pt);                (*pt)->fb = 0;                (*pt) = ptu;           }           else{                ptv = ptu->dir;                ptu->dir = ptv->esq;                ptv->esq = ptu;                (*pt)->esq = ptv->dir;                ptv->dir = (*pt);                if(ptv->fb ==1){                             (*pt)->fb = -1;                             }else{                                         (*pt)->fb = 0;                                }                if(ptu->fb == -1){                                      ptu->fb = 1;                                }else{                                ptu->fb = 0;                          }                                     (*pt) = ptv;            }            h = 0;            (*pt)->fb = 0;}void __caso2__(AVL **pt){     AVL *ptu,*ptv;         ptu = (*pt)->dir;         if(ptu->fb == -1){            (*pt)->dir = ptu->esq;             ptu->esq = (*pt);            (*pt)->fb = 0;            (*pt) = ptu;         }else{            ptv = ptu->esq;            ptu->esq = ptv->dir;            ptv->dir = ptu;            (*pt)->dir = ptv->esq;            ptv->esq = (*pt);            if(ptv->fb == -1){                            (*pt)->fb = 1;                            }else{                                (*pt)->fb = 0;                        }            if(ptv->fb == 1){                            ptu->fb = -1;                            }else{                               ptu->fb =0;                        }                            (*pt) = ptv;                    }      h = 0;     (*pt)->fb = 0;}