Académique Documents
Professionnel Documents
Culture Documents
h>
#include <stdlib.h>
#include <string.h>
//1) =====================================
typedef struct produit{
}produit;
//2)======================================
//a)
/*
typedef struct maillon{
produit pro;
struct maillon *next;
}maillon;
//b)
typedef struct stock{
maillon *head;
maillon *queue;
}ListStockS;
*/
//3)=================================
//a)
typedef struct maillonD{
produit pro;
struct maillonD *next;
struct maillonD *prev;
}maillonD;
//b)
maillonD *first;
maillonD *last;
int taille;
}stock;
//c)
stock *creer_stock(){
stock *pm=malloc(sizeof(stock));
if(pm==NULL)
return NULL;
pm->first=NULL;
pm->last=NULL;
pm->taille=0;
return pm;
}
maillonD *m=malloc(sizeof(maillonD));
if(m==NULL)
return NULL;
m->pro=prod;
m->next=NULL;
m->prev=NULL;
return m;
maillonD *m=creer_maillon(pro);
maillonD *temp=st->first;
if(st->first==NULL){
m->pro.Qnt=Qnt;
m->pro.PrixU=prixU;
st->first=st->last=m;
st->taille++;
return st;
}
else
while(temp!=NULL){
if(temp->pro.label==m->pro.label){
temp->pro.Qnt=(temp->pro.Qnt)+(m->pro.Qnt);
temp->pro.PrixU=m->pro.PrixU;
free(m);
return st;
}
temp=temp->next;
}
m->pro.Qnt=Qnt;
m->pro.PrixU=prixU;
m->next=st->first;
m->prev=NULL;
st->first->prev=m;
st->first=m;
st->taille++;
return st;
st->first=st->first->next;
st->first->prev=NULL;
free(temp);
st->taille--;
return st;
while(temp!=NULL){
if(temp->pro.label==pro.label){
break;
temp=temp->next;
//delete last
if(temp->next==NULL){
st->last=st->last->prev;
st->last->next=NULL;
free(temp);
st->taille--;
return st;
//delete middle
else{
temp->prev->next=temp->next;
temp->next->prev=temp->prev;
free(temp);
st->taille--;
return st;
}
return NULL;
}
//existe
if(st->first==NULL)
return NULL;
maillonD *temp=st->first;
while(temp!=NULL){
if(temp->pro.label==pro.label)
return st;
temp=temp->next;
}
return NULL;
//vendre
if(st->first==NULL)
return NULL;
maillonD *temp=st->first;
if(Existe(st,pro)==NULL){
printf("le produit n'existe pas dans le stock !");
}
else{
while(temp!=NULL){
if(temp->pro.label==pro.label)
break;
temp=temp->next;
temp->pro.Qnt=(temp->pro.Qnt)-Nb_unites;
if(temp->pro.Qnt==0)
st=supprimer(st,pro);
return st;
}
}
double PrixStock(stock *st){
if(st->first==NULL)
return 0;
double k=0;
maillonD *temp=st->first;
while(temp!=NULL){
k=k+temp->pro.PrixU;
temp=temp->next;
}
return k;
if(st->first==NULL)
printf("le stock est vide !");
maillonD *temp=st->first;
while(temp!=NULL){
int choix;
menu :
printf("\n\n");
printf("1. acheter produit\n");
printf("2. supprimer un produit\n");
printf("3. chercher si un livre existe ou non\n");
printf("4. vendre un livre\n");
printf("5. calculer le prix totale du stock\n");
printf("6. Quitter\n");
printf("\n---->Faites votre choix : ");
scanf("%d",&choix);
while(choix<1 && choix>6){
goto menu;
}
return choix;
}
// programme principale
int main() {
stock *st=creer_stock();
produit pro;
int choix=0;
int Qnt=0;
double PrixU=0;
int Nb_unites=0;
printf("%%%%%%%%%%%% Liste Doublement chainee : %%%%%%%%%%%%\n");
printf("inserer le label:");
scanf("%s",&pro.label);
printf("inserer la Qnt:");
scanf("%d",&Qnt);
printf("inserer le prix:");
scanf("%lf",&PrixU);
ajouter(st,pro,Qnt,PrixU);
affichage(st);
while(choix != 6){
choix=menu (st);
switch(choix){
case 1:
printf("inserer le label:");
scanf("%s",&pro.label);
printf("inserer la Qnt:");
scanf("%d",&Qnt);
printf("inserer le prix:");
scanf("%lf",&PrixU);
st=ajouter(st,pro,Qnt,PrixU);
affichage(st);
break;
case 2:
st=supprimer(st,pro);
if(st==NULL)
printf("le produit n'existe pas pour l'a
supprimer !");
affichage(st);
break;
case 3:
printf("inserer le label:");
scanf("%s",&pro.label);
printf("inserer la Qnt:");
scanf("%d",&Qnt);
printf("inserer le prix:");
scanf("%lf",&PrixU);
st=Existe(st,pro);
if(st==NULL)
printf("le produit n'existe pas !");
else
printf("le produit est trouver !");
affichage(st);
break;
case 4:
printf("inserer le label:");
scanf("%s",&pro.label);
printf("inserer la Qnt:");
scanf("%d",&Qnt);
printf("inserer le prix:");
scanf("%lf",&PrixU);
case 5:
printf(" le prix total du stock est :
%lf",PrixStock(st));
break;
}
}
return 0;
}