Accueil     Soft. MacOSX     Soft. MacOS/PC     PHP     Python     ROMS GBA     TP d'info     DBZ-GT     Martingales     Galeries     Liens     @  

TP5 Main

/* TP5 Main Fonctionne avec arbre.c et arbre.h 28/11/02 */
#include <stdio.h>
#include <malloc.h>
#include <Carbon.h> /* Sur Mac ! */
#include "arbre.h"

/* Prototypes */

UInt16 doRandomNumber(UInt16 minimum, UInt16 maximum);
void Infixe(AB a);
void Postfixe(AB a);
void Prefixe(AB a);

UInt16 doRandomNumber(UInt16 minimum, UInt16 maximum){
/* Cette fonction s'utilise que sur Mac !*/
UInt16randomNumber;
SInt32range, t;
randomNumber = Random();
range = maximum - minimum;
t = (randomNumber * range) / 65535;
return(t + minimum);
}

void Infixe(AB a) {
if (Arbre_vide(a)==FAUX) {
Infixe(a->g);
printf("%d,",a->e);
Infixe(a->d);
}
}

void Postfixe(AB a) {
if (Arbre_vide(a)==FAUX) {
Postfixe(a->g);
Postfixe(a->d);
printf("%d,",a->e);
}
}

void Prefixe(AB a) {
if (Arbre_vide(a)==FAUX) {
printf("%d,",a->e);
Prefixe(Fg(a));
Prefixe(Fd(a));
}
}

void Affichage(AB a) {
if (Arbre_vide(a)==FAUX) {
int i;
Affichage(a->g);
for(i=0;i<(20-Hauteur(a));i++)
printf(" ");
printf("%2d\n",a->e);
Affichage(a->d);
}
}

/* MAIN */

int main(void) {
AB a,b,c,uni,inter;
int i,j;
UInt32 seconds; /* Sur Mac !*/
/* Sur PC: srand(getpid()); */
GetDateTime(&seconds); /* Sur Mac !*/
SetQDGlobalsRandomSeed(seconds); /* Sur Mac !*/

a=Creer_AB();
b=Creer_AB();
a=Ajouter_AB(a,0);
b=Ajouter_AB(b,0);
for (i=0; i<10; i++) {
j=doRandomNumber(1,30); /* PC: rand()%10 */
c=Ajouter_AB(a,j);
j=doRandomNumber(1,30); /* PC: rand()%10 */
c=Ajouter_AB(b,j);
}

/* ©2002 All Rights Reserved to Didier STRAUS http://www.Software-DS.com*/
printf("\n\nInfixe: ");
Infixe(a);

printf("\n\nPostfixe: ");
Postfixe(a);

printf("\n\nPrefixe: ");
Prefixe(a);

printf("\n\n\nInfixe b: ");
Infixe(b);

printf("\n\nPostfixe b: ");
Postfixe(b);

printf("\n\nPrefixe b: ");
Prefixe(b);

uni=Union(a,b);
printf("\n\n\nInfixe Union: ");
Infixe(uni);

inter=Intersection(a,b);
printf("\n\nInfixe Intersection: ");
Infixe(inter);

printf("\n\nTaille: a=%d b=%d uni=%d\n\n",Taille(a),Taille(b),Taille(uni));
printf("\n©2002 All Rights Reserved to Didier STRAUS http://www.Software-DS.com\n");
return 0;
/* ©2002 All Rights Reserved to Didier STRAUS http://www.Software-DS.com*/
}





Haut de la page - Page précédente - Page générée en 0.03316 sec.
Recherche personnalisée
 

1843776 visiteurs.   ©2001-2023 All Rights Reserved to Software-DS.com
Made with a mac  
Confidentialité