1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct noeud *ABR;
typedef struct info
{ int Qte,num;
char date,Ncl,nom,prenom,Adr;
};
typedef struct noeud
{ struct info val;
ABR FD,FG;};
int arbrevide(ABR A)
{if (A==NULL)
return 1;
else
return 0;
};
ABR ajouter_cmnd(struct info cmnd,ABR FiD,ABR FiG)
{ABR p=malloc(sizeof(struct noeud));
p->val=cmnd;
p->FD=FiD;
p->FG=FiG;
return p;
};
ABR filsG(ABR A)
{
return (A->FG);
};
ABR filsD(ABR A)
{
return (A->FD);
};
int feuille(ABR A)
{
if ((arbrevide(filsG(A))==1) && (arbrevide(filsG(A))==1))
return 1;
else
return 0;
};
int Qtecmnd(ABR A)
{
return (A->val.Qte);
};
int numcmnd(ABR A)
{
return (A->val.num) ;
};
void newwcmnd(ABR *A,struct info v)
{
if (arbrevide(*A)==1)
*A=ajouter_cmnd(v,NULL,NULL);
else
{
if (v.Qte<Qtecmnd(*A))
newwcmnd(&(*A)->FG,v);
if (v.Qte>=Qtecmnd(*A))
newwcmnd(&(*A)->FD,v);
}
};
void traitercmnd(ABR *A,struct info *v)
{
if(arbrevide(*A)==0)
{
if(arbrevide((*A)->FD)==0)
traitercmnd(&(*A)->FD,&(*v));
else
{
if(feuille(*A)==1)
{*v=(*A)->val;
*A=NULL;}
else
{traitercmnd(&(*A)->FG,&(*v));
(*A)->val=*v;
}
}
}
};
void affchcmnd(ABR A)
{
if(arbrevide(A)==0)
{
printf("\n Numéro Commande: %d",A->val.num);
printf("\n Date Commande: %s",A->val.date);
printf("\n Numéro Client: %s",A->val.Ncl);
printf("\n Nom : %s",A->val.nom);
printf("\n Prénom: %s",A->val.prenom);
printf("\n Adresse: %s",A->val.Adr);
printf(" Quantitée Commandée %d \n **** \n",A->val.Qte);
}
};
void affchGrdQte(ABR A)
{
while (arbrevide(filsD(A))==0)
A=filsD(A);
affchcmnd(A);
};
int nbrcmnd(ABR A)
{
if(arbrevide(A)==1)
return 0;
else
return (1+nbrcmnd(filsD(A))+nbrcmnd(filsG(A)));
};
int Qtetotal(ABR A)
{ if (arbrevide(A)==1)
return 0;
else
return(Qtecmnd(A)+Qtetotal(filsG(A))+Qtetotal(filsD(A)));
};
void affchlst(ABR A)
{
if (arbrevide(A)==0)
{affchlst(filsD(A));
affchcmnd(A);
affchlst(filsG(A));
}
};
void main()
{int nbr=1,i,cont=0,choix=0;
ABR A;
struct info com;
A=(struct noeud*)malloc(sizeof(struct noeud));
A=NULL;
printf("Application GTCom \n Les fonctionalités Diponibles: \n -1- La Saisie des commandes \n -2- Supression des commandes \n -3- La commande contenu la plus grande quantité \n -4- Nombre des Commandes en attente \n -5- La quantitée commandée totale \n -6- Liste des commandes en attente");
do
{
printf("\n Entrer le code de la fonctionalité: ");
scanf("%d",&choix);
switch(choix)
{case 1:printf("\n Combien de commandes vous allez saisir?");
scanf("%d",&nbr);
for (i=0;i<nbr;i++)
{
printf("\n Le numéro de cette commande est: ");
scanf("%d",&com.num);
printf("\n la date du commande: ");
scanf("%s",&com.date);
printf("\n la le numéro du client: ");
scanf("%s",&com.Ncl);
printf("\n le nom du client: ");
scanf("%s",&com.nom);
printf("\n le prénom du client: ");
scanf("%s",&com.prenom);
printf("\n l'adresse du client: ");
scanf("%s",&com.Adr);
printf("\n La quantité commandée: ");
scanf("%d",&com.Qte);
newwcmnd(&A,com);
}
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
break;
case 2:traitercmnd(&A,&com);
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
break;
case 3:printf("\n la commande contenue la plus grande quantitée: \n");
affchGrdQte(A);
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
break;
case 4:printf("\n nombre des commandes en attente: %d",nbrcmnd(A));
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
break;
case 6:printf("\n la liste des commandes en attente");
affchlst(A);
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%c",&cont);
break;
case 5:printf("\n La quantitée commandée totale: %d ",Qtetotal(A));
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
break;
default:printf("\n Fonctionalité inéxistante");
printf("\n voulez vous faire d'autre fonctionalité?");
scanf("%d",&cont);
}
}while(cont!=0);
printf("\n ***END***");
} |
Partager