karlangadas

TREE: 5TAD

Nov 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "arbol.h"
  4. #include "lista.h"
  5. void camino(TBinaryTree *T,int ini,int fin){
  6.     TLista L;
  7.     Lista_Crear(&L);
  8.     TNode *q=T->root;
  9.     TNode *p=T->root;
  10.     TNode *r;
  11.     //Este primer bucle va a recorrer su descendencia en común
  12.     while (p==q){
  13.         Lista_InsertarIzq(&L, q->elem);
  14.         Lista_Eliminar(&L, r->elem);
  15.         r=q;
  16.         if (p->elem > ini) p=p->left;
  17.         else p=p->right;
  18.  
  19.         if (q->elem > fin) q=q->left;
  20.         else q=q->right;
  21.     }
  22.     //Ahora cada uno
  23.     while(p->elem!=ini){
  24.         Lista_InsertarIzq(&L, p->elem);
  25.         if (p->elem > ini) p=p->left;
  26.         else p=p->right;
  27.     }
  28.     Lista_InsertarIzq(&L, ini);
  29.    
  30.     while(q->elem != fin){
  31.         Lista_InsertarDer(&L, q->elem);
  32.        
  33.         if (q->elem > fin) q=q->left;
  34.         else q=q->right;
  35.     }
  36.     Lista_InsertarDer(&L, fin);
  37.    
  38.     Lista_Imprimir(L);
  39. }
  40. int main(){
  41.     TBinaryTree T;
  42.     init_tree(&T);
  43.     insert(&T,10);
  44.     insert(&T,6);
  45.     insert(&T,15);
  46.     insert(&T,4);
  47.     insert(&T,7);
  48.     insert(&T,13);
  49.     insert(&T,17);
  50.     insert(&T,0);
  51.     camino(&T,0,7);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment