int main(void) { creerPile(); empiler(42); // 42 empiler(9); // 9 // 42 int retour = depiler(); // retour = 9 return 0; }
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; }
TPartie* initialiser(Tparam *param){ int i = 0, j = 0; int nombreBateaux = 0; int casesOccupeBateaux = 0; TPartie *partie = malloc (sizeof(TPartie)); //On initialise le score partie->scorePlayer = 0; //=========== Initialisation / Allocation =================== partie->joueur = creerJoueur(); partie->machine = creerJoueur(); partie->grille = creerGrille(KHAUTGRILLE,KLARGGRILLE); partie->grilleMachine = creerGrille(KHAUTGRILLE, KLARGGRILLE); partie->parametres = param; partie->pileCoups = creerPile(); partie->scorePlayer = 0; //On compte le nombre de bateaux à allouer nombreBateaux = getNbBat(param); //On alloue partie->joueur->mesBateaux = malloc( sizeof(TBateau*) * nombreBateaux ); partie->machine->mesBateaux = malloc( sizeof(TBateau*) * nombreBateaux ); //=========== Préparation =================================== //Préparation des bateaux //Création des structures et ajout des id (commencent à 0) for(i = 0 ; i < nombreBateaux ; i++){ partie->joueur->mesBateaux[i] = creerBateau(); partie->machine->mesBateaux[i] = creerBateau(); partie->joueur->mesBateaux[i]->idBateau = i; partie->machine->mesBateaux[i]->idBateau = i + nombreBateaux; partie->joueur->mesBateaux[i]->estPlace = 0; partie->machine->mesBateaux[i]->estPlace = 0; } //Calcul du nombre de cases occupé par les bateaux //pour calculer le score for(i = 0 ; i < K_NBTYPEBATEAUX ; i++){ for(j = 0 ; j < partie->parametres->nombreInstanceBateaux[j] ; j++){ casesOccupeBateaux += i; } } partie->scorePlayer = KLARGGRILLE * KHAUTGRILLE + casesOccupeBateaux; return partie; }
void pileInit() { pileBloque = creerPile(); listeFonctionsDefinies = creerTableauDynamique(); }