NodePtr saisie_expression() { Pile* stack = creer_pile(); char c = '\0'; NodePtr tmp; while (c != '\n') { c = getchar(); switch (c) { case '+': case '*': tmp = creer_noeud(c, '\0'); tmp->right = depiler(stack); tmp->left = depiler(stack); empiler(stack, tmp); break; default: if (c >= '0' && c <= '9') // Si le caract�re saisi est un chiffre empiler(stack, creer_noeud('\0', c - '0')); // On l'empile on le convertissant en entier else if (c >= 'a' && c <= 'z') // Le caract�re est une variable empiler(stack, creer_noeud(c, '\0')); else if (c != '\n' && c != ' ') printf("Erreur de saisie.\n"); break; } } return depiler(stack); }
void ass_fctEnd(char* fctName) { PRINT_DEBUG(); printInst("5 %d %d\n", ADDR_SP, ADDR_CONTEXT); depiler(ADDR_CONTEXT); depiler(ADDR_R1); // depiler adresse de retour printInst("F %d\n", ADDR_R1); // goto R2 symboleT_endBloc(); // parameters }
/*@requires: p non NULL, p initalisée @assigns: p @ensures: on empile le sommet moins un puis le produit des deux derniers éléments (en ayant préalablement dépilé ces deux éléments), retourne 1 si l'opération est réussie, 0 sinon*/ void empiler_produit_deuxpremierselements(pile *p) { if(est_vide(*p)) return 0; int n, m; n = depiler(p); m = depiler(p); empiler(p, n*m); empiler(p, n-1); return 1; }
/*@requires: n >= 0 @assigns: rien @ensures: renvoie la factorielle de n*/ int factorielle2(int n) { if(n <= 0) return 1; pile p = creer_vide(); empiler(&p, n); empiler(&p, n-1); for(n = n-1; n > 0; n--) empiler_produit_deuxpremierselements(&p); depiler(&p); return depiler(&p); }
/*fonction chemin *param:structure matrice, la lettre à tester, le rand k correspondant à la Keme lettre du mot, structure redondance *verification (dans les 8 directions) si autour d'une lettre à tester se trouve la lettre au rang k+1 du mot a tester *si oui: on empile les coordonnées, on change de rang k et on continue a chercher la lettre suivante *sinon: on depile le chemin precedemment empile *condition de chaque if:ligne et colonne present dans la matrice / si la lettre recherchee est presente / si nous ne sommes pas déjà passé par la case(ligne,colonne) */ void chemin(t_case matrice[TAILLE_MATRICE][TAILLE_MATRICE],char lettre,int *k,t_coord redondance[TAILLE_MATRICE*TAILLE_MATRICE]){ //declaration int ligne=sommetpile_ligne(); int colonne=sommetpile_colonne(); //traitement //case ligne-1,colonne-1 if(ligne-1>=0 && colonne-1>=0 && matrice[ligne-1][colonne-1].lettre== lettre && !recherche_redondance(redondance,ligne-1,colonne-1)){ empiler(ligne-1,colonne-1); ajouter_coordonnee(redondance,ligne-1,colonne-1); *k=*k+1; } //case ligne-1,colonne else if(0<=ligne-1 && matrice[ligne-1][colonne].lettre== lettre && !recherche_redondance(redondance,ligne-1,colonne)){ empiler(ligne-1,colonne); ajouter_coordonnee(redondance,ligne-1,colonne); *k=*k+1; } //case ligne-1,colonne+1 else if(0<=ligne-1 && colonne+1<TAILLE_MATRICE && matrice[ligne-1][colonne+1].lettre== lettre && !recherche_redondance(redondance,ligne-1,colonne+1)){ empiler(ligne-1,colonne+1); ajouter_coordonnee(redondance,ligne-1,colonne+1); *k=*k+1; } //case ligne,colonne+1 else if(colonne+1<TAILLE_MATRICE && matrice[ligne][colonne+1].lettre==lettre &&!recherche_redondance(redondance,ligne,colonne+1)){ empiler(ligne,colonne+1); ajouter_coordonnee(redondance,ligne,colonne+1); *k=*k+1; } //case ligne+1,colonne+1 else if(ligne+1<TAILLE_MATRICE && colonne+1<TAILLE_MATRICE && matrice[ligne+1][colonne+1].lettre== lettre && !recherche_redondance(redondance,ligne+1,colonne+1)){ empiler(ligne+1,colonne+1); ajouter_coordonnee(redondance,ligne+1,colonne+1); *k=*k+1; } //case ligne+1,colonne else if(ligne+1<TAILLE_MATRICE && matrice[ligne+1][colonne].lettre== lettre && !recherche_redondance(redondance,ligne+1,colonne)){ empiler(ligne+1,colonne); ajouter_coordonnee(redondance,ligne+1,colonne); *k=*k+1; } //case ligne+1,colonne-1 else if(ligne+1<TAILLE_MATRICE && 0<=colonne-1 && matrice[ligne+1][colonne-1].lettre== lettre &&!recherche_redondance(redondance,ligne+1,colonne-1)){ empiler(ligne+1,colonne-1); ajouter_coordonnee(redondance,ligne+1,colonne-1); *k=*k+1; } //case ligne,colonne-1 else if(0<=colonne-1 && matrice[ligne][colonne-1].lettre== lettre && !recherche_redondance(redondance,ligne,colonne-1)){ empiler(ligne,colonne-1); ajouter_coordonnee(redondance,ligne,colonne-1); *k=*k+1; } //si la lettre recherchee n'est pas presente else{ depiler(); if(*k>0) *k=*k-1; } }
/*@requires: p initalisée @assigns: rien @ensures: retourne le produit des éléments de p et 1 si la pile est vide*/ int produit_pile(pile p) { int sommet; int ret = 1; while(!estVide(&p)) ret *= depiler(&p); return ret; }
/*@requires: p non NULL, p initalisée @assigns: p @ensures: duplique l'élément au sommet de la pile, retourne 1 si l'opération est réussie, 0 sinon*/ void dupliquer_sommet(pile *p) { if(est_pleine(*p)) return 0; int sommet = depiler(p); empiler(p, sommet); empiler(p, sommet); return 1; }
/*@requires: p non NULL, p initalisée @assigns: p @ensures: on a empilé la valeur du sommet actuel diminué de 1, retourne 1 si l'opération est réussie, 0 sinon*/ void empiler_moins_un(pile *p) { if(est_pleine(*p)) return 0; int sommet = depiler(p); empiler(p, sommet); empiler(p, sommet - 1); return 1; }
void freeStack(pile p) { if (!p) return; while (!estVideP(p)) { int v; depiler(&p, &v); } free(p); }
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; }
/* * Supprime une pile (vide ou pleine). * Dépile l'ensemble des éléments de la pile puis désallocation. */ void supprimerPile (struct Pile * pile) { /* Suppression de la pile */ while (pile->taille > 0) { depiler(pile); } /* Désallocation de la pile */ free(pile); }
/* * Supprime une pile (vide ou pleine). * Dépile l'ensemble des éléments de la pile puis désallocation. */ void supprimerPile (struct Pile * pile) { /* Suppression de la pile */ /* Suppression de chaque élément de la pile */ for (int i = 0; i < pile->taille; i++) { depiler(pile); } /* Désallocation de la pile */ free(pile); }
void main () { typePile *pile; char expr [TAILLEMAX]; int val; char *ptexpr; typeNoeud *feuille, *noeud, *droit, *gauche; typeNoeud *racine; pile = initpile (TAILLEPILE); ptexpr = expr; printf ("Entrer une expression postfixee\n"); fgets (expr, TAILLEMAX, stdin); while (*ptexpr == ' ') ptexpr++; while ( *ptexpr != '=' && *ptexpr != '\n' ) { if (!isdigit (*ptexpr)) { droit = depiler(pile); gauche = depiler(pile); noeud = creerNoeud (*ptexpr, gauche, droit); empiler (pile, noeud); ptexpr++; } else { sscanf (ptexpr, "%d", &val); while (isdigit(*ptexpr)) ptexpr++; feuille = creerFeuille (val); empiler (pile, feuille); } while (*ptexpr == ' ') ptexpr++; } racine = depiler(pile); printf ("\nExpression infixee : \n"); infixe (racine); printf ("\n\n"); printf ("Expression prefixee : \n"); prefixe (racine); printf ("\n\n"); printf ("Valeur de l'expression : %d\n", eval (racine)); }
/* FONCTION : free_lifo * Libère la lifo (lifo_t). * * entree : le pointeur de la lifo (lifo_t) * sortie : le code d'erreur (int) */ void free_lifo(lifo_t* p) { type_t tmp; while (! lifo_vide(p)) { tmp = depiler(p); free(*tmp); *tmp = NULL; } free(p->tab); free(p); p = NULL; }
int comparer(char * exp) { int i=0; int boolean=0; Pile p=NULL; while((&exp[i]!=NULL)&&(boolean!=0)){ if ((exp[i]=='{')||(exp[i]=='(')||(exp[i]=='[')){ empiler(&p,exp[i]); i++; }else if ((exp[i]=='}')&&(p->valeur=='{')){ depiler(&p); i++; }else if ((exp[i]==')')&&(p->valeur=='(')){ depiler(&p); i++; }else if ((exp[i]==']')&&(p->valeur=='[')){ depiler(&p); i++; }else{ boolean = 1; return 1; } return 0; } int main(int argc, char * argv[]) { int r; printf("%s\n",argv[1]); r =comparer(argv[1]); printf("%d \n",r); return 0; }
int main(void) { creerPile(); empiler(42); // 42 empiler(9); // 9 // 42 int retour = depiler(); // retour = 9 return 0; }
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 action(int act) { nodeType *t1, *t2; switch (act) { case 1: //-----------nouvelle case tab t1 = depiler(); t2 = depiler(); A[nameToIndexGPL(t2->name)] = t1; tailleForet++; break; case 2: //-----------genAtom empiler(genAtomGPL(recherche(dicos->dicoNT, NONTERMINAL, val_scan()), action_scan(), NONTERMINAL)); break; case 3: //-----------genUnion t1 = depiler(); t2 = depiler(); empiler(genUnion(t2, t1)); break; case 4: //-----------genConc t1 = depiler(); t2 = depiler(); empiler(genConc(t2, t1)); break; case 5: //-----------genAtome empiler(genAtomGPL(recherche(dicos->dicoT, TERMINAL, val_scan()), action_scan(), TERMINAL)); break; case 6: //-----------genStar t1 = depiler(); empiler(genStar(t1)); break; case 7: //-----------genUn t1 = depiler(); empiler(genUn(t1)); break; default: printf("erreur action numéro %d", act); break; } }
void inversion_pile(lifo_t * p) { /*variables locales*/ fifo_t * f = NULL; /*file*/ type_t tmp; /*valeurs a afficher*/ int err; /*erreur*/ /*initialisation*/ f = (fifo_t *)malloc(sizeof(fifo_t)); err = init_fifo(f,p->t_max); if (! err) { printf("Pile a inverser :\n"); afficher_lifo(p); /*parcours de la pile*/ while (!lifo_vide(p)) { tmp = depiler(p); /*passage des valeurs*/ enfiler(f,tmp); } printf("Etat de la file :\n"); afficher_fifo(f); while (! fifo_vide(f)) { tmp = defiler(f); /*passage des valeurs*/ empiler(p,tmp); } /*liberation de la file*/ free_fifo(f); } printf("Pile inversee :\n"); afficher_lifo(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); }
/******************************************************************************************************************************* ***************************************************** menu_heterogene ***********************************************************/ void menuu2(PileGe pg,Pile* p){ printf("\t***********************************************************************\n"); printf("\t*************************** Pile Generique Heterogene *****************\n"); printf("\t***********************************************************************\n"); printf("\t*********************** 1. Tester si la pile est vide ***********\n"); printf("\t*********************** 2. Empiler un Element ***********\n"); printf("\t*********************** 3. Depiler ***********\n"); printf("\t*********************** 4. Visualiser le sommet de la pile ***********\n"); printf("\t*********************** 5. Retour au menu precedent ***********\n"); int i=0; printf("\tn="); scanf("%d",&i); switch (i){ case 1:{ system("cls"); if(est_vide(p)) printf("\tLa pile est vide\n"); else{ printf("\tLa pile n'est pas vide\n"); } menuu2(pg,p); break; } case 2:{ system("cls"); int choix; printf("\t1. Empiler un Int\n"); printf("\t2. Empiler un Livre\n"); scanf("%d",&choix); if(choix==1){ int in; printf("\tEnter le int a empiler:\n n="); scanf("%d",&in); empiler(p,in,entier); } else{ char ID[20]; printf("\tL'ID : "); scanf("%s",ID); char Titre[20]; printf("\tLe titre : "); scanf("%s",Titre); char Auteur[20]; printf("\tL'auteur : "); scanf("%s",Auteur); int np; printf("\tLe numero de pages dan ce livre : "); scanf("%d",&np); int j,m,y; printf("\tLa Date de publication en format jj/mm/yy : "); char a,b; scanf("%d %c %d %c %d",&j,&a,&m,&b,&y); Date dd=cred(j,m,y); Livre liv=crel(ID,Titre,Auteur,np,dd); empiler(p,nv_livre(ID,Auteur,Titre,np,j,m,y),livre); } menuu2(pg,p); break; } case 3:{ system("cls"); depiler(p); menuu2(pg,p); break; } case 4:{ system("cls"); printf("le sommet de la pile est :"); Element *E; E=p->tete; if(E!=NULL){ Afficher_element(E->donnee); } printf("\n"); menuu2(pg,p); break; } case 5:{ system("cls"); menuu(pg,p); break; } default :{ system("cls"); printf("Votre choix est invalide !!\n"); menuu2(pg,p); } } }
/* Fonction min-max permettant de déterminer ou jouer - le meilleur coup est stocké dans *ti et *tj - joueur est le joueur devant joue le meilleur coup - joueur_actif est le joueur jouant le tour actuel - depth = profondeur actuelle dans l'arbre de recherche - max-depth = profondeur maximale, la récursion s'arrête si on l'atteind */ int min_max(othello* jeu, char joueur, char joueur_actif, int nb_coups, int*ti, int*tj, int depth, int max_depth){ int meilleur_score =-1; int cur_score; int i, j; typedef struct coord_meilleur_coup{ int ligne; int colonne;} coord_MC; //structure des coordonnées d'un meilleur coup int compteur_mc= 0; //compteur de meilleur coup coord_MC tab[TAILLE*TAILLE]; /* tableau stockant chaque meilleur coup possible */ /* Si la partie est finie ou si on a atteind la profondeur maximale -> on renvoie le score du plateau */ if(partie_finie(nb_coups, 0)||depth == max_depth){ meilleur_score = score(jeu, joueur_actif, depth, nb_coups); } else { //on parcours toutes les positions for(i=0; i<TAILLE; i++){ for(j=0; j<TAILLE; j++){ //si on a un coup possible on renvoi le meilleur coup a jouer if(coup_possible(jeu, joueur_actif, i, j)){ empiler(*jeu); jouer_un_coup(jeu, joueur_actif, i, j); cur_score = min_max(jeu, joueur, adversaire(joueur_actif), nb_coups+1, ti, tj, depth+1, max_depth); depiler(jeu); if(joueur_actif == joueur){ meilleur_score = -1000; if(cur_score > meilleur_score){ meilleur_score = cur_score; *ti = i; *tj = j; tab[compteur_mc].ligne = i; tab[compteur_mc].colonne = j; } compteur_mc++; } if(joueur_actif == adversaire(joueur)){ meilleur_score = 1000; if(cur_score < meilleur_score){ meilleur_score = cur_score; *ti = i; *tj = j; tab[compteur_mc].ligne = i; tab[compteur_mc].colonne = j; } compteur_mc++; } } //endif coup_possible() } } if(compteur_mc > 0){ int al = rand()%compteur_mc; *ti = tab[al].ligne; *tj = tab[al].colonne; } else{ *ti =-1; *tj =-1; } } /* pour tous les coups possibles sauvegarder le jeu (empiler) jouer ce coup score = appel récursif de min_max avec les paramètres mis à jour restaurer le jeu (dépiler) Si c'est à nous de jouer -> conserver le score max et le coup correspondant Si c'est à l'adversaire de jouer -> conserver le score min et le coup correspondant S'il y a au moins 1 meilleur coup possible mettre le coup correspondant dans ti et tj Amélioration : choisir aléatoirement un coup parmis les meilleurs possibles Sinon mettre -1,-1 dans ti et tj renvoyer le score */ return meilleur_score; }
/** * @brief Résout un puzzle * @param[in,out] p le puzzle à résoudre * @param[in] t le damier initial * @param[in,out] os flux de sortie */ void jouer(Puzzle& p, const Tab2D& t, std::ostream& os) { Etat etatInitial; Etat etatCourant; Tab2D damierFinal; Etat etatDerive; double tempsDebutRecherche = getTime(); but(damierFinal, t.nbL, t.nbC); initialiser(etatInitial.damier, t.nbL, t.nbC); etatInitial.mouvement = FIXE; etatInitial.precedent = 0; etatInitial.g = 0; //Copie du damier inititial dans etatInitial for (unsigned int l = 0; l < t.nbL; ++l) { for (unsigned int c = 0; c < t.nbC; ++c) { etatInitial.damier.tab[l][c] = t.tab[l][c]; } } etatInitial.h = manhattan(etatInitial.damier, damierFinal); initialiser(etatDerive.damier, t.nbL, t.nbC); inserer(p.lEAE, 0, etatInitial); //étatInitial dans LEAE bool solutionTrouvee = false; bool mvtPossible; unsigned int pos; while (p.lEAE.nb != 0) { pos = minimal(p.lEAE); etatCourant = lire(p.lEAE, pos); //on prend le 1er état à explorer //insérer étatCourant dans LEE inserer(p.lEE, longueur(p.lEE), etatCourant); supprimer(p.lEAE, pos); //supprimer étatCourant de LEAE if (etatCourant.h == 0) { // le damier de étatCourant est le damier but solutionTrouvee = true; break; //sortir de la boucle while } /*pour_tout (mouvement possible associé à étatCourant) mouvement possible relatif à damier de étatCourant (etatCourant.damier) ordre d'exploration (obligatoire) NORD, EST, SUD, OUEST */ //initialiser un étatDérivé // d'après le mouvement for(int m = OUEST; m >= NORD; --m) { mvtPossible = deriver(etatCourant, (Mouvement) m, etatDerive); if (mvtPossible && !rechercher(etatDerive, p.lEAE)\ && !rechercher(etatDerive, p.lEE)) { etatDerive.precedent = longueur(p.lEE) - 1; etatDerive.h = manhattan(etatDerive.damier, damierFinal); etatDerive.g = etatCourant.g + 1; //insérer étatDérivé dans LEAE inserer(p.lEAE, longueur(p.lEAE), etatDerive); } } } double tempsFinRecherche = getTime(); cout << "Durée de recherche : " << tempsFinRecherche - tempsDebutRecherche <<" seconde(s)."<< endl; if (solutionTrouvee) { Pile sol; Etat etatSol; initialiser(sol, 3, 2); initialiser(etatSol.damier, t.nbL, t.nbC); //Stockage de la solution etatSol = lire(p.lEE, longueur(p.lEE)-1); empiler(sol, etatSol); while (etatSol.precedent != 0) { etatSol = lire(p.lEE, etatSol.precedent); empiler(sol, etatSol); } empiler(sol, etatInitial); //Affichage de la solution os << "Damier : " << t.nbL << " lignes " << t.nbC << " colonnes" << endl; os << "Solution en " << sol.sommet << " mouvements" << endl; while (!estVide(sol)) { afficher(sommet(sol), os); os << endl; depiler(sol); } detruire(sol); detruire(etatSol.damier); } else { os << "Solution non trouvée" << endl; } detruire(etatInitial.damier); detruire(etatCourant.damier); detruire(etatDerive.damier); detruire(damierFinal); }
void annulerDernierCoup(TPartie *partie) { int i = 0; int idBatCase; Coup * dernierCoup; TBateau * bateauCible; TPosition positionBat; Coord positionCourante; // Récupération du sommet de la pile et remise à l'état normal // Machine ------ dernierCoup = sommet(partie->pileCoups); idBatCase = getIdBateauSurCase(partie->grille, dernierCoup->coordTir); //Si il y a un bateau sur la case if(idBatCase >= 0) { bateauCible = getBateauFromId(idBatCase); positionBat = getPosBateau(bateauCible); positionCourante.noCol = positionBat.x; positionCourante.noLin = positionBat.y; // Si le bateau est coulé, on repasse tout à touché if(estCoule(bateauCible)) { for(i=0;i<getTypeBateau(bateauCible);i++) { bateauCible->etat[i] = TOUCHE; setEtatCase(partie->grille, positionCourante, GRILLE_CASE_TOUCHE); if(positionBat.direction == HORIZONTAL) positionCourante.noCol += 1; else if(positionBat.direction == VERTICAL) positionCourante.noLin += 1; } } // On traite la case du coup à proprement parler positionCourante.noCol = positionBat.x; positionCourante.noLin = positionBat.y; if(positionBat.direction == HORIZONTAL) i = dernierCoup->coordTir.noCol - positionCourante.noCol; else if(positionBat.direction == VERTICAL) i = dernierCoup->coordTir.noLin - positionCourante.noLin; bateauCible->etat[i] = INTACT; } setEtatCase(partie->grille, dernierCoup->coordTir, GRILLE_CASE_NORMAL); // On dépile le coup partie->pileCoups = depiler(partie->pileCoups); // Joueur ------- //On ajoute 1 au score pour le coup tiré partie->scorePlayer = partie->scorePlayer + 1; dernierCoup = sommet(partie->pileCoups); idBatCase = getIdBateauSurCase(partie->grilleMachine, dernierCoup->coordTir); if(idBatCase >= 0) { bateauCible = getBateauFromId(idBatCase); positionBat = getPosBateau(bateauCible); positionCourante.noCol = positionBat.x; positionCourante.noLin = positionBat.y; // Si le bateau est coulé, on repasse tout à touché if(estCoule(bateauCible)) { for(i=0;i<getTypeBateau(bateauCible);i++) { bateauCible->etat[i] = TOUCHE; setEtatCase(partie->grilleMachine, positionCourante, GRILLE_CASE_TOUCHE); if(positionBat.direction == HORIZONTAL) positionCourante.noCol += 1; else if(positionBat.direction == VERTICAL) positionCourante.noLin += 1; } } // On traite la case du coup à proprement parler positionCourante.noCol = positionBat.x; positionCourante.noLin = positionBat.y; if(positionBat.direction == HORIZONTAL) i = dernierCoup->coordTir.noCol - positionCourante.noCol; else if(positionBat.direction == VERTICAL) i = dernierCoup->coordTir.noLin - positionCourante.noLin; bateauCible->etat[i] = INTACT; } setEtatCase(partie->grilleMachine, dernierCoup->coordTir, GRILLE_CASE_NORMAL); // On dépile le coup partie->pileCoups = depiler(partie->pileCoups); }
void detruire(Pile *p) { while(*p != NULL) free(depiler(&(*p))); }
void ass_print() { PRINT_DEBUG(); depiler(ADDR_R0); printInst("C %d\n", ADDR_R0); }
t_graphe *parcours_profondeur(t_graphe* graphe, char *n_s) { int *visite; int *names; t_pile *pile; int s; int u; int v; int i; int succ; int size; t_ch_int *tmp; t_ch_ch_int *ttmp; t_graphe *T; void *data; u = 0; v = 0; data = 0; succ = 0; size = taille(graphe); visite = xmalloc(sizeof(*visite)*size); names = xmalloc(sizeof(*names)*size); pile = xmalloc(sizeof(*pile)); pile->pile = xmalloc(sizeof(*pile->pile)*size); pile->taille_pile = 0; T = init(GO); empiler(name_to_number(graphe, n_s), pile); for (i = 0, ttmp = graphe->graphe; i < size; i++, ttmp = ttmp->next) names[i] = ttmp->number; inserer(get_index(s, names, size), visite); while (pile->taille_pile != 0) { u = sommet(pile); succ = 0; for (ttmp = graphe->graphe; ttmp != NULL; ttmp = ttmp->next) if (ttmp->number == u) break; for (tmp = ttmp->liste; tmp != NULL; tmp = tmp->next) if (!visite[get_index(tmp->number, names, size)]) succ++; if (succ != 0) { for (ttmp = graphe->graphe; ttmp != NULL; ttmp = ttmp->next) if (ttmp->number == u) break; for (tmp = ttmp->liste; tmp != NULL; tmp = tmp->next) if (!visite[get_index(tmp->number, names, size)]) { v = tmp->number; data = tmp->data; break; } ajouterArc(T, number_to_name(graphe, u), number_to_name(graphe, v), data); empiler(v,pile); inserer(get_index(v, names, size), visite); } else depiler(pile); } return (T); }
int main (void) { /* Declaration d'un objet pile */ typePile *pile; // VARIABLES STD char expr [TAILLEMAX]; int val; char *ptexpr; // VARIABLES DE L'ARBRE typeNoeud *feuille, *noeud, *droit, *gauche; typeNoeud *racine; // Pointe sur la racine de l'arbre // INIT PILE pile = initpile (TAILLEPILE); // POINTEUR SUR L'EXPRESSION ENTREE ptexpr = expr; // DEMANDE EXPRESSION A L'UTILISATEUR printf ("Entrer une expression postfixee\n"); fgets (expr, TAILLEMAX, stdin); //------------------------------------------------- // COMMENCER LE TRAITEMENT DE L'OPERATION POSTFIXEE //------------------------------------------------- // SAUTER LES BLANCS DU DEBUT while (*ptexpr == ' ') ptexpr++; /* L'expression se termine sur = ou \n */ while ( *ptexpr != '=' && *ptexpr != '\n' ) { if (!isdigit (*ptexpr)) { /* On a un operateur dans *ptexpr */ droit = depiler(pile); /* Depiler le fils droit */ //3 gauche = depiler(pile); /* Depiler le fils gauche */ //4 noeud = creerNoeud (*ptexpr, gauche, droit); //5 empiler (pile, noeud); /* Empiler le sous arbre */ //6 ptexpr++; } else { /* On a un operande dont la valeur est dans val */ sscanf (ptexpr, "%d", &val); while (isdigit(*ptexpr)) ptexpr++; /* Sauter les digits */ feuille = creerFeuille (val); //1 empiler (pile, feuille); /* Empiler le noeud */ //2 } while (*ptexpr == ' ') ptexpr++; /* Sauter les blancs */ } racine = depiler(pile); // La racine est le dernier ÈlÈment de la pile printf ("\nExpression infixee : \n"); infixe (racine); /* Parcours infixe de l'arbre obtenu */ printf ("\n\n"); printf ("Expression prefixee : \n"); prefixe (racine); /* Parcours prÈfixe de l'arbre obtenu */ printf ("\n\n"); printf ("Valeur de l'expression : %d\n", eval (racine)); system ("pause"); }
void ass_popResult(int reg) { PRINT_DEBUG(); depiler(ADDR_R0 + reg); }