pEmploye chercherEmployePile(pPile p, int num) { pPile p2 = creerPile(); pEmploye pE=NULL; pEmploye pE2=NULL; if(p == NULL) { perror("erreur: pile.c : fonction chercherEmployePile: pointeur NULL"); return NULL; } if (pileVide(p)) { printf("erreur: pile.c : fonction chercherEmployePile: la Pile est vide\n"); return NULL; } while(!pileVide(p)) { pE2 = SommetEmploye(p); if((pE2->num) == num) { pE = pE2; break; } else { depiler(p); empiler(p2,pE2); } } while(!pileVide(p2)) { pE2 = depiler(p2); empiler(p,pE2); } supprimerPile(p2); return pE; }
pEmploye SommetEmploye( pPile p ) { if(p == NULL) { perror("erreur: pile.c : fonction SommetEmploye: pointeur NULL"); return NULL; } if (pileVide(p)) { printf("erreur: pile.c : fonction SommetEmploye: la Pile est vide\n"); return NULL; } return p->tabEmploye[ p->iSommet ]; }
pEmploye depiler( pPile p ) { pEmploye pE; if(p == NULL) { perror("erreur: pile.c : fonction depiler: pointeur NULL"); return NULL; } if (pileVide(p)) { printf("erreur: pile.c : fonction depiler: la Pile est vide\n"); return NULL; } pE = p->tabEmploye[ p->iSommet ]; p->iSommet = p->iSommet-1; return pE; }
void supprimerPile(pPile p) { pEmploye pE; if(p == NULL) { perror("erreur: pile.c : fonction supprimerPile: pointeur NULL"); return; } while(!pileVide(p)) { pE = depiler(p); free(pE); } free(p); }
void libererPartie(TPartie *partie){ int i; int nombreBateaux = getNbBat(partie->parametres); //On libère tout les bateaux for(i=0;i<nombreBateaux;i++) { libererBateau(partie->joueur->mesBateaux[i]); libererBateau(partie->machine->mesBateaux[i]); } libererJoueur(partie->joueur); libererJoueur(partie->machine); libererGrille(partie->grille); libererGrille(partie->grilleMachine); libererParam(partie->parametres); //On libère la pile de coups while(!pileVide(partie->pileCoups)) partie->pileCoups = depiler(partie->pileCoups); free(partie); }
Arbre* constArbre(Elm* t, int n) { /*Transformation de forme infixée au forme postfixée*/ Pile *p; initPile(&p); p = infexeeAuPostfixee(t, n); /*création de l'arbre*/ Arbre* f; Arbre* f1; Arbre* f2; /*initialiser la pile des Arbres*/ PileAebre* pArbre; initPileA(&pArbre); Elm x; while(!pileVide(p)) { depiler(&p, &x); if(operande(x)) { f = creatFeuil(x); empilerA(&pArbre, f); } else { /*construire une sous arbre*/ f = creatFeuil(x); depilerA(&pArbre, &f1); depilerA(&pArbre, &f2); f->succ_d = f1; f->succ_g = f2; empilerA(&pArbre, f); } } /*la racine de l'arbre se trouve a la pile des arbres et la pile p est vide*/ return sommetPileA(pArbre); }