Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "arbol.h"
- int CompruebaSubArbol(TNode *node1,TNode *node2){
- if (node2==NULL)
- return 1;
- if (node2->elem!=node1->elem)
- return 0;
- return CompruebaSubArbol(node1->left,node2->left) && CompruebaSubArbol(node1->right,node2->right);
- }
- int esSubArbol(TBinaryTree *T,TBinaryTree *D){
- TNode *q=T->root;
- while(q->elem!=D->root->elem && q!=NULL){
- if (q->elem>D->root->elem) q=q->left;
- else q=q->right;
- }
- if (q!=NULL)
- return CompruebaSubArbol(q,D->root);
- return 0;
- }
- int main(){
- TBinaryTree T;
- init_tree(&T);
- TBinaryTree D;
- init_tree(&D);
- insert(&T,10);
- insert(&T,6);
- insert(&T,15);
- insert(&T,4);
- insert(&T,7);
- insert(&T,13);
- insert(&T,17);
- insert(&T,0);
- insert(&D,6);
- insert(&D,4);
- insert(&D,7);
- printf("%d\n",esSubArbol(&T,&D));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment