Trouver un fichier de code source :
   

Version Française - English Version
Accueil > 

C++

 > 

DESSINER UNE ARBRE BINAIRE( MODE CONSOLE):

 > 

BT bell/BinaryTree/tree.c


DESSINER UNE ARBRE BINAIRE( MODE CONSOLE):

BT bell/BinaryTree/tree.c


Informations sur ce code source

Cliquez pour voir la capture en taille normale
Code Source DESSINER UNE ARBRE BINAIRE( MODE CONSOLE):
Auteur benzarabel
Fichier BT bell/BinaryTree/tree.c en C / C++ / C++.NET
Publié le 16/11/2011

Bonjour; car il est défficile d'imaginer la représentation d'une arbre binaire, je vous présente un code en c qui dessin une arbre binaire de recherche sur le console. Voir le Snapshot (capture) pour etre convaincus de télecharger le code :)
 

Fichier : BT bell/BinaryTree/tree.c

Nombre de lignes : 316 lignes


Afficher ce fichier en plein écran
  • #include"tree.h"
  • #include<stdio.h>
  • #include<stdlib.h>
  • #include<conio.h>
  • #include<math.h>
  • #define true 1
  • #define false 0
  • int dx=1;
  • int dy=2;
  • TArbre NouvelArbreVide( void )
  • {
  • return NULL;
  • }
  • void Ajouter( TArbre* arbre , int val )
  • {
  • if( *arbre == NULL )
  • {
  • *arbre = ( TArbre )malloc( sizeof( TNoeud ) );
  • (*arbre)->valeur = val ;
  • (*arbre)->gauche = NULL ;
  • (*arbre)->droit = NULL ;
  • }
  • else
  • {
  • if( val < (*arbre)->valeur )
  • {
  • Ajouter( &(*arbre)->gauche , val ) ;
  • }
  • else
  • {
  • Ajouter( &(*arbre)->droit , val ) ;
  • }
  • }
  • }
  • //**************************************************************
  • int chercher(TArbre arbre,int v)
  • {
  • int trouve=false;
  • while(arbre&&!trouve)
  • {
  • if(arbre->valeur==v)
  • trouve=true;
  • else
  • {
  • if(v<arbre->valeur)
  • arbre=arbre->gauche;
  • else
  • arbre=arbre->droit;
  • }
  • }//while
  • return trouve;
  • }
  • //**************************************************************
  • void Afficher1( TArbre arbre )
  • {
  • if( arbre != NULL )
  • {
  • printf( "%d " , arbre->valeur ) ;
  • Afficher1( arbre->gauche ) ;
  • Afficher1( arbre->droit ) ;
  • }
  • }
  • void Afficher2( TArbre arbre )
  • {
  • textcolor(10);
  • if( arbre != NULL )
  • {
  • Afficher2( arbre->gauche ) ;
  • printf( "%d " , arbre->valeur ) ;
  • Afficher2( arbre->droit ) ;
  • }
  • }
  • void Afficher3( TArbre arbre )
  • {
  • if( arbre != NULL )
  • {
  • Afficher3( arbre->gauche ) ;
  • Afficher3( arbre->droit ) ;
  • printf( "%d " , arbre->valeur ) ;
  • }
  • }
  • //**************************************************************
  • int NombreElements( TArbre arbre )
  • {
  • if( arbre == NULL )
  • {
  • return (0) ;
  • }
  • else
  • {
  • return( 1 + NombreElements( arbre->gauche ) + NombreElements( arbre->droit ) ) ;
  • }
  • }
  • //**************************************************************
  • int Hauteur( TArbre arbre )
  • {
  • int hg=0,hd=0,h=0 ;
  • if( arbre == NULL )
  • h=0;
  • else
  • {
  • hg = Hauteur( arbre->gauche ) ;
  • hd = Hauteur( arbre->droit ) ;
  • h=(hg>hd?hg:hd)+1;
  • }
  • return h;
  • }
  • //***************************************************************
  • int Somme( TArbre arbre )
  • {
  • if( arbre == NULL )
  • {
  • return (0) ;
  • }
  • else
  • {
  • return ( arbre->valeur + Somme( arbre->droit ) + Somme( arbre->gauche ) ) ;
  • }
  • }
  • //***************************************************************
  • int delElement(TArbre* arbre, int info)
  • {
  • TArbre temp=NULL; //pointeur temporaire pour le free
  • TArbre temp2=NULL;
  • int infotemp=0;
  • int ElementSupprime=false;
  • if(*arbre == NULL)
  • ElementSupprime=false;
  • else
  • {
  • if((*arbre)->valeur<info)
  • ElementSupprime=delElement(&(*arbre)->droit,info);
  • else if((*arbre)->valeur>info)
  • ElementSupprime=delElement(&(*arbre)->gauche,info);
  • else
  • {
  • ElementSupprime=true;//on a trouvé notre élément
  • if((*arbre)->gauche==NULL)//rien a gauche
  • {
  • temp=*arbre;
  • (*arbre)=(*arbre)->droit;//on suit vers la droite
  • free(temp);
  • }//!head->fg
  • else//il ya a gauche
  • {
  • if((*arbre)->droit==NULL)//rien a droite
  • {
  • temp=*arbre;
  • (*arbre)=(*arbre)->gauche;//on suit vers la gauche
  • free(temp);
  • }
  • else//il y a aussi a droite
  • {
  • //il faut remplacer l'élément par le plus petit élément de son
  • //sous arbre droit
  • //on va chercher le plus petit
  • temp=(*arbre);
  • //on va déplacer temp d'un cran à droite
  • temp=temp->droit;
  • while(temp->gauche)
  • {
  • temp2=temp;//on garde le précédent
  • temp=temp->gauche;
  • }
  • //ici, temp n'a plus de fils gauche, c'est donc le plus petit élément
  • //on le supprime
  • infotemp=temp->valeur;//on conserve l'info
  • if(temp->droit) //il y a du monde a droite, on bouge notre arbre
  • {
  • temp2->gauche=temp->droit;//fait un pont
  • free(temp);//on libère notre élément
  • }
  • //on peut faire remonter l'info
  • (*arbre)->valeur=infotemp;
  • ElementSupprime=true;//ok suppression effectuée
  • }
  • }//if head->fg!=NULL
  • }
  • }//head != NULL
  • return ElementSupprime;
  • }
  • //***********************************************************
  • int nb_pos(int a)
  • {
  • int ret;
  • int b=a;
  • for(ret=1;a/10;ret++,a/=10);
  • if (b<0) ret++;
  • return ret;
  • }
  • void DrawTree_Horizonral(TArbre arbre,char type, int x, int y,int level)
  • {
  • if(arbre!=NULL)
  • {
  • int a=level-1;
  • switch (type)
  • {
  • case 'r'://racine
  • /*on calcule les coordonées du racine slon le profonder de l'arbre ...*/
  • x=1;
  • y=pow(2,Hauteur(arbre)-1);
  • gotoxy(x,y);
  • printf("[%d]",arbre->valeur);
  • printf("%c%c",196,180);
  • DrawTree_Horizonral(arbre->droit,'d',x+nb_pos(arbre->valeur)+3,y-1,Hauteur(arbre));
  • DrawTree_Horizonral(arbre->gauche,'g',x+nb_pos(arbre->valeur)+3,y+1,Hauteur(arbre));
  • break;
  • case 'd'://droit
  • while(a>=0)
  • {
  • a--;
  • gotoxy(x,y);
  • y--;
  • printf("%c",179);
  • }
  • gotoxy(x,y);
  • printf("%c",218);
  • textcolor(10);
  • printf("(%d)",arbre->valeur);
  • textcolor(15);
  • printf("%c%c",196,180);
  • DrawTree_Horizonral(arbre->droit,'d',x+nb_pos(arbre->valeur)+2+2,y-1,Hauteur(arbre)-1);
  • DrawTree_Horizonral(arbre->gauche,'g',x+nb_pos(arbre->valeur)+2+2,y+1,Hauteur(arbre)-1);
  • break;
  • case 'g'://gauche
  • textcolor(15);
  • while(a>=0)
  • {
  • a--;
  • gotoxy(x,y);
  • y++;
  • printf("%c",179);
  • }
  • gotoxy(x,y);
  • printf("%c",192);
  • textcolor(12);
  • printf("(%d)",arbre->valeur);
  • textcolor(15);
  • printf("%c%c",196,180);
  • DrawTree_Horizonral(arbre->droit,'d',x+nb_pos(arbre->valeur)+2+2,y-1,Hauteur(arbre)-1);
  • DrawTree_Horizonral(arbre->gauche,'g',x+nb_pos(arbre->valeur)+2+2,y+1,Hauteur(arbre)-1);
  • break;
  • }
  • }else
  • {
  • gotoxy(x,y);
  • if(type=='d')
  • printf("%c%c",218,196);
  • else
  • printf("%c%c",192,196);;
  • textcolor(14);
  • printf("%c",16);
  • textcolor(7);
  • //printf("%c%c",196,180);
  • }
  • }
  • /*
  • */


Liste des fichiers du ZIP

FichierTaille
BT bell/BinaryTree/BinaryTree.cbp1,14 Ko
BT bell/BinaryTree/BinaryTree.depend563 o
BT bell/BinaryTree/BinaryTree.layout340 o
BT bell/BinaryTree/main.c1004 o
BT bell/BinaryTree/obj/Debug/main.o3,02 Ko
BT bell/BinaryTree/obj/Debug/tree.o8,19 Ko
BT bell/BinaryTree/tree.c6,72 Ko
BT bell/BinaryTree/tree.h815 o
BT bell/conio/conio/conio.h4,6 Ko
BT bell/conio/conio/libconio.a11,24 Ko
BT bell/conio/how to install.txt562 o
BT bell/snapshot.jpg52,34 Ko

Pour télécharger le zip au complet, veuillez vous rendre sur cette page :
Télécharger DESSINER UNE ARBRE BINAIRE( MODE CONSOLE):


Sources du même auteur ayant un ZIP


Voir la suite...


Sources du même langage comportant un zip


Voir la suite...





Logiciels à télécharger...

  • Devis-Factures PHMSD (2.1.0.1)
    Devis-Factures PHMSD (2.1.0.1)
    Configuration minimale Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à jour) - Processeur 500 Mhz (700 Mhz conseillé) - 256 Mo de Ram - 100 Mo d'espace disque disponible po...
  • Ludoprêt (3.2) [Gratuit / Freeware]
    Ludoprêt (3.2) [Gratuit / Freeware]
    Logiciel gratuit de gestion de ludothèque. Gestion des jeux et des adhérents. Gestion des forfaits et des cotisations. Gestion des prêts et retours. Gestion des retards et édition des relances. ...
  • Revealer Keylogger Free (2.05) [Gratuit / Freeware]
    Revealer Keylogger Free (2.05) [Gratuit / Freeware]
    Keylogger invisible et gratuit pour Windows 8, 7, Vista ou XP. Revealer Keylogger Free vous permet de surveiller l'activité des utilisateurs de votre ordinateur et d'enregistrer toutes les touches du ...

Sondage...

Le top des photos

Photo ??Photo ???????????????
Photo ????????Photo ????????
 

Développement réalisé par Nicolas SOREL (Nix) et Emmanuel (EBArtSoft) avec l'aide de Cyril DURAND, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,45 sec