Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "tree.h"
- void duplicarArbol(TNode *node1, TTree *arbol2);
- int insertarNodo2(TNode *node,TNode *nuevo);
- int insertar2(TTree *tree, TData data);
- int main(){
- TTree arbol;
- TTree arbol2;
- crearArbol(&arbol);
- crearArbol(&arbol2);
- insertar(&arbol,2);
- insertar(&arbol,1);
- insertar(&arbol,3);
- duplicarArbol(arbol.root,&arbol2);
- preorden(arbol2.root);
- return 0;
- }
- void duplicarArbol(TNode *node1, TTree *arbol2){
- if(node1 == NULL)
- return ;
- insertar2(arbol2,node1->info);
- insertar2(arbol2,node1->info);
- duplicarArbol(node1->izq,arbol2);
- duplicarArbol(node1->der,arbol2);
- }
- int insertarNodo2(TNode *node,TNode *nuevo){
- if(node->info <= nuevo->info){
- if(node->der == NULL){
- node->der = nuevo;
- return 1;
- }else
- return insertarNodo2(node->der,nuevo);
- }
- if(node->info > nuevo->info){
- if(node->izq == NULL){
- node->izq = nuevo;
- return 1;
- }else
- return insertarNodo2(node->izq,nuevo);
- }
- }
- int insertar2(TTree *tree, TData data){
- TNode *nuevo = malloc(sizeof(TNode));
- nuevo->info = data;
- nuevo->izq = NULL;
- nuevo->der = NULL;
- if(arbolVacio(tree)){
- tree->root = nuevo;
- }else{
- insertarNodo2(tree->root,nuevo);
- }
- }
Add Comment
Please, Sign In to add comment