int main(int argc, char *argv[]) { file * f1 = creer_file(); printf("Création file 1\n"); afficher_file(f1); enfiler(f1, 50); enfiler(f1, 25); enfiler(f1, 2); enfiler(f1, 7); printf("Affichage file 1\n"); afficher_file(f1); printf("Défile file 1\n"); defiler(f1); afficher_file(f1); enfiler(f1, 7); printf("Enfile file 1\n"); afficher_file(f1); file * f2 = creer_file(); enfiler(f2, 3); enfiler(f2, 4); enfiler(f2, 5); printf("Création file 2\n"); afficher_file(f2); printf("Concaténation file 1 et 2\n"); concatener_files(f1, f2); afficher_file(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); defiler(f1); printf("Défiler file 1\n"); afficher_file(f1); printf("File 1 est vide : "); printf("%d\n", file_estVide(f2)); destruction(f2); destruction(f1); return 0; }
int* kPartitioning(double ** comm, int n, int k, int * constraints, int nb_constraints, int greedy_trials) { /* ##### declarations & allocations ##### */ PriorityQueue Qpart, *Q = NULL, *Qinst = NULL; double **D = NULL; int deficit, surplus, *part = NULL; int real_n = n-nb_constraints; part = build_p_vector(comm, n, k, greedy_trials, constraints, nb_constraints); memory_allocation(&Q, &Qinst, &D, real_n, k); /* ##### Initialization ##### */ initialization(part, comm, &Qpart, Q, Qinst, D, real_n, k, &deficit, &surplus); /* ##### Main loop ##### */ while((nextGain(&Qpart, Q, &deficit, &surplus))>0) { algo(part, comm, &Qpart, Q, Qinst, D, real_n, &deficit, &surplus); } /* ##### Balancing the partition ##### */ balancing(real_n, deficit, surplus, D, part); /*if partition isn't balanced we have to make one last move*/ /* ##### Memory deallocation ##### */ destruction(&Qpart, Q, Qinst, D, real_n, k); return part; }
~history_tracker() { BOOST_ASSERT(destruction() == 0); // assert: object not previously destroyed ++_dtor; if (log()) *log() << " object " << this << " destructor\n"; }
// destructor SortSetList::~SortSetList() { if (mainNodePointer != NULL) { destruction(mainNodePointer); delete mainNodePointer; mainNodePointer = NULL; } }
void Commande (char code, unsigned int valeur) { fichier << "Début commande" << std::endl; switch(code) { case 'E': { Afficher(MESSAGE, "case E"); fichier << "Case 'E'" << std::endl; destruction(); break; } case 'A': { Afficher(MESSAGE, "case A"); fichier << "Case 'A'" << std::endl; Voiture voiture = {TypeUsager::AUTRE, compteurImmatriculation, -1}; compteurImmatriculation = (compteurImmatriculation++) % IMMATRICULATION_MAX; if (valeur == 1) { write(descEcritureCanauxBarriereEntree[AUTRE_BLAISE_PASCAL - 1], &voiture, sizeof(Voiture)); } else { write(descEcritureCanauxBarriereEntree[ENTREE_GASTON_BERGER - 1], &voiture, sizeof(Voiture)); } break; } case 'P': { Afficher(MESSAGE, "case P"); fichier << "Case 'P'" << std::endl; Voiture voiture = {TypeUsager::PROF, compteurImmatriculation, -1}; compteurImmatriculation = (compteurImmatriculation++) % IMMATRICULATION_MAX; if (valeur == 1) { write(descEcritureCanauxBarriereEntree[PROF_BLAISE_PASCAL - 1], &voiture, sizeof(Voiture)); } else { write(descEcritureCanauxBarriereEntree[ENTREE_GASTON_BERGER - 1], &voiture, sizeof(Voiture)); } break; } case 'S': { Afficher(MESSAGE, "case S"); fichier << "Case 'S'" << std::endl; write(descEcritureCanalBarriereSortie, &valeur, sizeof(unsigned int)); break; } default: fichier << "default" << std::endl; Afficher(MESSAGE, "Commande: code inconnue"); } fichier << "Fin commande" << std::endl; }
void history_tracker_dump(OS& os) { os << default_construction() << " default_construction\n"; os << construction() << " construction\n"; os << copy_construction() << " copy_construction\n"; os << copy_assignment() << " copy_assignment\n"; os << move_construction() << " move_construction\n"; os << move_assignment() << " move_assignment\n"; os << destruction() << " destruction\n"; }
void Commande (char code, unsigned int valeur) { switch(code) { case 'E': { destruction(); break; } case 'A': { Voiture voiture = {TypeUsager::AUTRE, compteurImmatriculation, -1}; compteurImmatriculation = (compteurImmatriculation + 1) % IMMATRICULATION_MAX; if (valeur == 1) { write(descEcritureCanauxBarriereEntree[AUTRE_BLAISE_PASCAL - 1], &voiture, sizeof(Voiture)); } else { write(descEcritureCanauxBarriereEntree[ENTREE_GASTON_BERGER - 1], &voiture, sizeof(Voiture)); } break; } case 'P': { Voiture voiture = {TypeUsager::PROF, compteurImmatriculation, -1}; compteurImmatriculation = (compteurImmatriculation + 1) % IMMATRICULATION_MAX; if (valeur == 1) { write(descEcritureCanauxBarriereEntree[PROF_BLAISE_PASCAL - 1], &voiture, sizeof(Voiture)); } else { write(descEcritureCanauxBarriereEntree[ENTREE_GASTON_BERGER - 1], &voiture, sizeof(Voiture)); } break; } case 'S': { write(descEcritureCanalBarriereSortie, &valeur, sizeof(unsigned int)); break; } default: Afficher(MESSAGE, "Commande: code inconnue"); } }
void destruction(Etats E) { if (E != NULL) destruction(E->suiv); free(E); }
//cette fonction prends une position et explose la bombe au bout de 3 sec puis on tue ce processus void explos_bomb (int pos,joueur* J,int longueur) { char buf[BUF]="\0"; int nbr; char nb[2]="\0"; //Debut decrementation de nbr bombe int fd=open("donnee",O_RDWR); if(J->num==1) { lseek(fd,15,SEEK_SET); read(fd,buf,1); nbr=atoi(buf); nbr=nbr-1; sprintf(nb,"%d",nbr); lseek(fd,15,SEEK_SET); write(fd,nb,1); } if(J->num==2) { lseek(fd,40,SEEK_SET); read(fd,buf,1); nbr=atoi(buf); nbr=nbr-1; sprintf(nb,"%d",nbr); lseek(fd,40,SEEK_SET); write(fd,nb,1); } //FIN decrementation de nbr bombe sleep(3); //Debut incrementation de nbr bombe car la bombe a explosé if(J->num==1) { lseek(fd,15,SEEK_SET); read(fd,buf,1); nbr=atoi(buf); nbr=nbr+1; sprintf(nb,"%d",nbr); lseek(fd,15,SEEK_SET); write(fd,nb,1); } if(J->num==2) { lseek(fd,40,SEEK_SET); read(fd,buf,1); nbr=atoi(buf); nbr=nbr+1; sprintf(nb,"%d",nbr); lseek(fd,40,SEEK_SET); write(fd,nb,1); } close (fd); //Fin incrementation de nbr bombe car la bombe a explosé int fd1=open("live",O_RDWR); int a=1,b=1,c=1,d=1; int b1=0,b2=0,b3=0,b4=0; //pr les bonus qui seront effacé dans la sous map int it1=0,it2=0,it3=0,it4=0; for(int i=1;i<=(J->puissance);i++) { lseek(fd1,pos+S_MAP,SEEK_SET); write(fd1,"+",1); lseek(fd1,(pos+(i*1)),SEEK_SET); read(fd1,buf,1); if((strcmp(buf," ")==0||strcmp(buf,"A")==0||strcmp(buf,"B")==0||strcmp(buf,"*")==0||strcmp(buf,"@")==0) && a==1) { lseek(fd1,S_MAP+(pos+(i*1)),SEEK_SET); write(fd1,"+",1); } else { if(((strcmp(buf,"1")==0||strcmp(buf,"2")==0||strcmp(buf,"3")==0)||strcmp(buf,"0")==0) && a==1) { lseek(fd1,S_MAP+(pos+(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"*")==0) {b1=1;it1=S_MAP+(pos+(i*1));} if(strcmp(buf,"@")==0) {b1=2;it1=S_MAP+(pos+(i*1));} lseek(fd1,S_MAP+(pos+(i*1)),SEEK_SET); write(fd1,"+",1); } a=0; } lseek(fd1,(pos-(i*1)),SEEK_SET); read(fd1,buf,1); if((strcmp(buf," ")==0||strcmp(buf,"A")==0||strcmp(buf,"B")==0||strcmp(buf,"*")==0||strcmp(buf,"@")==0) && b==1) { lseek(fd1,S_MAP+(pos-(i*1)),SEEK_SET); write(fd1,"+",1); } else { if((strcmp(buf,"1")==0||strcmp(buf,"2")==0||strcmp(buf,"3")==0 ||strcmp(buf,"0")==0) && b==1 ) { lseek(fd1,S_MAP+(pos-(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"*")==0) {b2=1;it2=S_MAP+(pos-(i*1));} if(strcmp(buf,"@")==0) {b2=2;it2=S_MAP+(pos-(i*1));} lseek(fd1,S_MAP+(pos-(i*1)),SEEK_SET); write(fd1,"+",1); } b=0; } lseek(fd1,(pos+(i*longueur)+i*1),SEEK_SET); read(fd1,buf,1); if((strcmp(buf," ")==0||strcmp(buf,"A")==0||strcmp(buf,"B")==0||strcmp(buf,"*")==0||strcmp(buf,"@")==0) && c==1) { lseek(fd1,S_MAP+(pos+(i*longueur)+i*1),SEEK_SET); write(fd1,"+",1); } else { if((strcmp(buf,"1")==0||strcmp(buf,"2")==0||strcmp(buf,"3")==0||strcmp(buf,"0")==0) && c==1) { lseek(fd1,S_MAP+(pos+(i*longueur)+i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"*")==0) {b3=1;it3=S_MAP+(pos+(i*longueur)+i*1);}; if(strcmp(buf,"@")==0) {b3=2;it3=S_MAP+(pos+(i*longueur)+i*1);} lseek(fd1,S_MAP+(pos+(i*longueur)+i*1),SEEK_SET); write(fd1,"+",1); } c=0; } lseek(fd1,(pos-(i*longueur)-i*1),SEEK_SET); read(fd1,buf,1); if((strcmp(buf," ")==0||strcmp(buf,"A")==0||strcmp(buf,"B")==0||strcmp(buf,"*")==0||strcmp(buf,"@")==0) && d==1) { lseek(fd1,S_MAP+(pos-(i*longueur)-i*1),SEEK_SET); write(fd1,"+",1); } else { if((strcmp(buf,"1")==0||strcmp(buf,"2")==0||strcmp(buf,"3")==0||strcmp(buf,"0")==0) && d==1) { lseek(fd1,S_MAP+(pos-(i*longueur)-i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"*")==0) {b4=1;it4=S_MAP+(pos-(i*longueur)-i*1);} if(strcmp(buf,"@")==0) {b4=2;it4=S_MAP+(pos-(i*longueur)-i*1);} lseek(fd1,S_MAP+(pos-(i*longueur)-i*1),SEEK_SET); write(fd1,"+",1); } d=0; } } verif_ssmap(); point_vie(3); destruction(); sleep(1); // Nous allons supprimé le souffle /********/ for(int i=1;i<=(J->puissance);i++) { lseek(fd1,pos,SEEK_SET); read(fd1,buf,1); if((strcmp(buf,"X")==0)) { lseek(fd1,pos,SEEK_SET); write(fd1," ",1); } // on supprime le souffle dans notre map principal Si il y a un plus alors on remplace par un espace //Gauche lseek(fd1,(pos-(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,(pos-(i*1)),SEEK_SET); write(fd1," ",1); } //cas ou ya un bonus pris dans le souffle alors on le supprime if(strcmp(buf,"*")==0 || strcmp(buf,"@")==0) { lseek(fd1,(pos-(i*1)),SEEK_SET); write(fd1," ",1); } //Droite lseek(fd1,(pos+(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,(pos+(i*1)),SEEK_SET); write(fd1," ",1); } if(strcmp(buf,"*")==0 || strcmp(buf,"@")==0) { lseek(fd1,(pos+(i*1)),SEEK_SET); write(fd1," ",1); } //Bas lseek(fd1,(pos+(i*longueur)+i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,(pos+(i*longueur)+i*1),SEEK_SET); write(fd1," ",1); } if(strcmp(buf,"*")==0 || strcmp(buf,"@")==0) { lseek(fd1,(pos+(i*longueur)+i*1),SEEK_SET); write(fd1," ",1); } //Haut lseek(fd1,(pos-(i*longueur)-i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,(pos-(i*longueur)-i*1),SEEK_SET); write(fd1," ",1); } if(strcmp(buf,"*")==0 || strcmp(buf,"@")==0) { lseek(fd1,(pos-(i*longueur)-i*1),SEEK_SET); write(fd1," ",1); } // On supprime le souffle dans notre sous map lseek(fd1,pos+S_MAP,SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,pos+S_MAP,SEEK_SET); write(fd1," ",1); } lseek(fd1,S_MAP+(pos+(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,S_MAP+(pos+(i*1)),SEEK_SET); write(fd1," ",1); } lseek(fd1,S_MAP+(pos-(i*1)),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,S_MAP+(pos-(i*1)),SEEK_SET); write(fd1," ",1); } lseek(fd1,S_MAP+(pos+(i*longueur)+i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,S_MAP+(pos+(i*longueur)+i*1),SEEK_SET); write(fd1," ",1); } lseek(fd1,S_MAP+(pos-(i*longueur)-i*1),SEEK_SET); read(fd1,buf,1); if(strcmp(buf,"+")==0) { lseek(fd1,S_MAP+(pos-(i*longueur)-i*1),SEEK_SET); write(fd1," ",1); } //On remet les bonus ou il etais dans la sous map si un des mur a ete detruit if(b1==1) { lseek(fd1,it1,SEEK_SET); write(fd1,"*",1); } if(b1==2) { lseek(fd1,it1,SEEK_SET); write(fd1,"@",1); } if(b2==1) { lseek(fd1,it2,SEEK_SET); write(fd1,"*",1); } if(b2==2) { lseek(fd1,it2,SEEK_SET); write(fd1,"@",1); } if(b3==1) { lseek(fd1,it3,SEEK_SET); write(fd1,"*",1); } if(b3==2) { lseek(fd1,it3,SEEK_SET); write(fd1,"@",1); } if(b4==1) { lseek(fd1,it4,SEEK_SET); write(fd1,"*",1); } if(b4==2) { lseek(fd1,it4,SEEK_SET); write(fd1,"@",1); } } close (fd1); verif_ssmap(); /****/ kill(getpid(),SIGKILL); }