Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * arbolbb.c
- *
- * Created on: 21 mar. 2019
- * Author: alumno
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <errno.h>
- #include "arbolbb.h"
- void crear(T_Arbol* arbol){
- (*arbol)=NULL;
- }
- // Destruye la estructura utilizada y libera la memoria.
- void destruir(T_Arbol* arbol){
- if((*arbol)!=NULL){
- destruir(&(*arbol)->izq);
- destruir(&(*arbol)->der);
- free((void*)arbol);
- }
- }
- // Inserta num en el árbol. Si ya está insertado, no hace nada
- void insertar(T_Arbol* arbol,unsigned num){
- if((*arbol)==NULL){
- (*arbol)=(T_Arbol)malloc(sizeof(struct T_Nodo));
- (*arbol)->dato=num;
- (*arbol)->izq=NULL;
- (*arbol)->der=NULL;
- }else{
- if((*arbol)->dato < num ){
- insertar(&(*arbol)->der,num);
- }else if((*arbol)->dato > num){
- insertar(&(*arbol)->izq,num);
- }
- }
- }
- // Muestra el contenido del árbol en InOrden
- void mostrar(T_Arbol arbol){
- if(arbol != NULL){
- mostrar(arbol->izq);
- printf("%d\t",arbol->dato);
- mostrar(arbol ->der);
- }
- }
- // Guarda en disco el contenido del fichero
- void salvar(T_Arbol arbol, FILE* fichero){
- if(fichero != NULL){
- if(arbol != NULL){
- salvar(arbol->izq,fichero);
- fwrite(&(arbol->dato),sizeof(int),1,fichero);
- salvar(arbol ->der,fichero);
- }
- }else
- perror("Fichero recibido nulo \n");
- fclose(fichero);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement