Ejemplo n.º 1
0
        public async void depiler(Canvas c, Canvas Algo)
        //Dépilement d'une valeur de la pile
        {
            Algo algo = new Algo(24, coordX_Algo, coordY_Algo); //Initialisation de l'algorithme

            algo.afficher(Algo);                                //Affichage del'algorithme
            Point[] tabpt2 = new Point[2];                      //tableau pour le déplacement pendant la disparition
            tabpt2[0].X = coordX;
            tabpt2[0].Y = coordY - 60;
            tabpt2[1].X = coordX + 400;
            tabpt2[1].Y = tabpt2[0].Y - 200;
            if (this.sommetPile > 0) // Si il y a une valeur dans la pile
            {
                comPrincipal.Text           = "Dépilement en cours ...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Yellow;
                comPrincipal.apparaitre(1);
                sommetPile--;
                tabpt[0].X = this.tab[sommetPile].CoordX;
                tabpt[0].Y = this.tab[sommetPile].CoordY;
                this.tab[sommetPile].colorChamp(couleur_Deplace_dans_Pile, couleur_Deplace_dans_Pile, 1);
                this.tab[sommetPile].disappear(tabpt2, 2);//Faire disparaitre la case (valeur)
                comPrincipal.disparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(.6));
            }
            else
            {
                comPrincipal.Text           = "  Pile vide !";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(1.3);
                comPrincipal.disparaitre(1.5);
            }
            algo.disparaitre(Algo); //Disparaitre l'algorithme
        }
Ejemplo n.º 2
0
        public async Task deFiler(Canvas c, Canvas Algo)
        {
            Algo algo = new Algo(26, coordX_Algo, coordY_Algo);

            Point[] tabpt2 = new Point[2];//tableau pour le déplacement pendant la disparition
            tabpt2[0].X = this.tab[0].CoordX + widthOfcase;
            tabpt2[0].Y = this.tab[0].CoordY;
            tabpt2[1].X = tabpt2[0].X + 100;
            tabpt2[1].Y = tabpt2[0].Y - 100;
            algo.afficher(Algo);
            if (this.sommetFile > 0)
            {
                comPrincipal.Text           = "DéFilment en cours ...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Yellow;
                comPrincipal.apparaitre(1);
                sommetFile--;
                tabpt[0].X = this.tab[sommetFile].CoordX;
                tabpt[0].Y = this.tab[sommetFile].CoordY;

                this.tab[0].colorChamp(couleur_Deplace_dans_File, couleur_Deplace_dans_File, 1);
                this.tab[0].disappear(tabpt2, 2);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                comPrincipal.disparaitre(.5);


                for (int i = 0; i < sommetFile; i++)//decalage interfile
                {
                    comPrincipal.Text           = "Décalage  ...";
                    comPrincipal.CouleurFond    = couleur_Deplace_dans_File;
                    comPrincipal.CouleurBordure = couleur_Deplace_dans_File;
                    comPrincipal.apparaitre(1);


                    this.tab[i] = this.tab[i + 1];
                    tabpt[0].X  = this.tab[i].CoordX + widthOfcase;
                    this.tab[i].deplacer(tabpt, 1);

                    this.tab[i].colorChamp(couleur_Deplace_dans_File, couleur_Deplace_dans_File, 1);
                    await Task.Delay(TimeSpan.FromSeconds(.5));

                    this.tab[i].colorChamp(couleurFondFile, couleurBordureCase, 1);



                    tabpt[0].X = this.tab[i].CoordX - widthOfcase;
                    comPrincipal.disparaitre(.5);
                }
            }
            else
            {
                comPrincipal.Text           = "    File vide !";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(1.3);
                comPrincipal.disparaitre(1.5);
            }
            algo.disparaitre(Algo);
        }
Ejemplo n.º 3
0
        public async void empiler(int val, Canvas c, Canvas Algo)
        // Empilement d'une valeur
        {
            Algo algo = new Algo(23, coordX_Algo, coordY_Algo);

            algo.afficher(Algo);//Affichage de l'algorithme

            if (this.sommetPile < tailleMaxPile)
            {
                comPrincipal.Text           = "Empilement en cours ...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Yellow;
                comPrincipal.apparaitre(1);

                this.tab[sommetPile] = new Case(val, this.coordX, this.coordY - (heightOfcase + 10), 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                this.tab[sommetPile].Forme.Opacity = 0.7;
                this.tab[sommetPile].afficher(c); //Affichage d'une nouvelle case

                await Task.Delay(TimeSpan.FromSeconds(.6));

                this.tab[sommetPile].deplacer(tabpt, 1);                                                  //Déplacer la case pour l'empiler
                this.tab[sommetPile].colorChamp(couleur_Deplace_dans_Pile, couleur_Deplace_dans_Pile, 1); //colorer la case


                tabpt[0].Y = this.tab[sommetPile].CoordY - heightOfcase;

                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                this.tab[sommetPile].colorChamp(couleurFondPile, couleurBordureCase, 1);


                sommetPile++;
                comPrincipal.disparaitre(.5);
            }
            else
            {
                comPrincipal.Text           = "  Pile pleine !";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(1.3);
                comPrincipal.disparaitre(1.5);
            }
            algo.disparaitre(Algo);// Disparaitre l'algorithme
        }
Ejemplo n.º 4
0
        public async Task enFiler(int val, Canvas c, Canvas Algo)
        {
            Algo algo = new Algo(25, coordX_Algo, coordY_Algo);

            algo.afficher(Algo);

            if (this.sommetFile < tailleMaxFile)
            {
                comPrincipal.Text           = "Enfilment en cours ...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Yellow;
                comPrincipal.apparaitre(1);

                this.tab[sommetFile] = new Case(val, this.coordX - (widthOfcase + 10), this.coordY, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                this.tab[sommetFile].afficher(c);
                this.tab[sommetFile].Forme.Opacity = 0.7;
                await Task.Delay(TimeSpan.FromSeconds(.4));

                this.tab[sommetFile].deplacer(tabpt, 1);
                this.tab[sommetFile].colorChamp(couleur_Deplace_dans_File, couleur_Deplace_dans_File, 1);


                tabpt[0].X = this.tab[sommetFile].CoordX - widthOfcase;

                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                this.tab[sommetFile].colorChamp(couleurFondFile, couleurBordureCase, 1);
                sommetFile++;

                comPrincipal.disparaitre(.5);
            }

            else
            {
                comPrincipal.Text           = "    File plien !";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(1.3);
                comPrincipal.disparaitre(1.5);
            }
            algo.disparaitre(Algo);
        }
Ejemplo n.º 5
0
        public async Task suppression(int valeur, Canvas c, Commentaire comPrincipal, Canvas Alg)
        {
            int[] tabInfo = new int[2];                                   //Le tableau qui sera modifié par la fonction de recherche
            await recherche(valeur, tabInfo, c, true, comPrincipal, Alg); //Il retourne un entier qui décrit l'echec (0) ou la réussite (1) de la recherche ainsi que la position

            comPrincipal = new Commentaire("Suppression en cours ...", Brushes.Black, this.coordX, this.coordY - 150, 150, 70, Brushes.PaleGreen, Brushes.White);
            Algo algo = new Algo(7, coordX_Algo, coordY_Algo);

            if (tabInfo[0] == 1)
            {
                Commentaire com = new Commentaire("On décrémente la taille du tableau", Brushes.Black, this.coordX + this.tab[tabInfo[1]].Width * tabInfo[1], this.coordY - tab[0].Height, 200, 30, Brushes.GreenYellow, Brushes.White);
                com.ajouterCanvas(c);                           //On crée le commentaire qui explique l'avacncement de l'algorithme
                Point[] tabl = new Point[3];
                if (this.triee && (tabInfo[1] < tailleTab - 1)) //Cas trié, on traitera le cas où la valeur recherchée se trouve à la fin du tableau à part
                {
                    algo.afficher(Alg);
                    await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 1, Temps.time);

                    com.Text    = "On décale toutes les cases suivantes";
                    com.Width   = 200;
                    com.Height += 20;
                    com.apparaitre(0);                                              //On adapte le commentaire au contexte
                    tabl[0] = new Point(tabInfo[1] * widthOfcase + coordX, coordY); //On fait disparaître la case à supprimer
                    this.tab[tabInfo[1]].disappear(tabl, 1);
                    int i;
                    for (i = tabInfo[1]; i < this.tailleTab - 1; i++)       //On effectue les décalages
                    {
                        await algo.colorer(couleurAlgo, 2, Temps.time);

                        tabl[0] = new Point(i * widthOfcase + coordX, coordY);
                        this.tab[i + 1].deplacer(tabl, 1);
                        await algo.colorer(couleurAlgo, 3, Temps.time);

                        await Task.Delay(TimeSpan.FromSeconds(Champ.time));

                        this.tab[i] = this.tab[i + 1];
                        await algo.colorer(couleurAlgo, 4, Temps.time);
                    }
                    await algo.colorer(couleurAlgo, 5, Temps.time);

                    await algo.colorer(couleurAlgo, 6, Temps.time);

                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                    algo.disparaitre(Alg);
                }
                else if (tabInfo[1] != tailleTab - 1)     //Cas non trié, supression d'un élément au milieu
                {
                    com.Text    = "On remplace le contenu de la case\npar celui de la dernière case\net on décrémente la taille";
                    com.Width   = 200;
                    com.Height  = 70;
                    com.CoordX  = com.CoordX - this.tab[0].Width;
                    com.CoordY -= 30;
                    com.apparaitre(0);                                              //On adapte le commentaire et on l'affiche
                    tabl[0] = new Point(tabInfo[1] * widthOfcase + coordX, coordY); //La case à supprimer disparaît sur place
                    this.tab[tabInfo[1]].disappear(tabl, 1);
                    this.tab[tabInfo[1]] = this.tab[this.tailleTab - 1];            //On reemplcae la première valeur par la dernière
                    tabl[0] = new Point((tailleTab - 1) * widthOfcase + coordX, coordY - heightOfcase);
                    tabl[1] = new Point(tabInfo[1] * widthOfcase + coordX, coordY - heightOfcase);
                    tabl[2] = new Point(tabInfo[1] * widthOfcase + coordX, coordY); //On définit les points par où passe la case à déplacer
                    this.tab[tailleTab - 1].deplacer(tabl, 3);                      //Animation du remplacement
                    await Task.Delay(TimeSpan.FromSeconds(Champ.time));

                    com.disparaitre(Champ.time);
                }
                else                                                                //Cas non trié, suppression d'un élément à la fin
                {
                    tabl[0] = new Point(tabInfo[1] * widthOfcase + coordX, coordY); //Gestion de l'animation (disparition de la dernière case)
                    this.tab[tabInfo[1]].disappear(tabl, 1);
                }
                this.tailleTab--;                      //On décrémente la taille
                this.tabIndices[tailleTab].masquer(c); //On masque Le dernier indice
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                com.enleverCanvas(c);                     //Fin de l'animation
                comPrincipal.CouleurFond = Brushes.Green; //Commentaire de réussite de la suppression
                comPrincipal.Text        = "Suppression réussie";
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            else                                        //Cas de non suppression (élément non trouvé)
            {
                comPrincipal.CouleurFond = Brushes.Red; //Commentaire d'échec de suppression
                comPrincipal.Text        = "Suppression impossible\nélément non trouvé";
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
        }
Ejemplo n.º 6
0
        private async Task rechercheSeq(int val, int[] tabInfo, Canvas c, Boolean insSup, Commentaire comPrincipal, Canvas Alg)
        {
            //Effectue une recherche séquentiel dans le tableau tab
            // tabInfo[0] correspond au boolean trouv et tabInfo[1] correspond à l'indice de la valeur val si il est trouvée sinon l'indice ou devrait être insérée cette valeur .
            // inserSup est un boolean qui indique si il ya une insertion ou suppression aprés cette recherche
            int i = 0;

            tabInfo[0] = 0;
            SolidColorBrush couleurparcours = Brushes.Red;
            SolidColorBrush couleurtrouve   = Brushes.Green;
            Commentaire     com             = new Commentaire(" ", Brushes.Black, this.tab[i].CoordX - 5, this.tab[i].CoordY - 35, 50, 50, couleurparcours, couleurparcours);
            Algo            algo            = new Algo(1, coordX_Algo, coordY_Algo);

            algo.afficher(Alg);
            com.ajouterCanvas(c);
            com.opacity = 0;
            com.Height  = 30;
            com.Width   = 160;
            await algo.colorer(couleurAlgo, 0, Temps.time);

            await algo.colorer(couleurAlgo, 1, Temps.time);

            await algo.colorer(couleurAlgo, 2, Temps.time);

            while (i < this.tailleTab & tabInfo[0] == 0)
            {
                await algo.colorer(couleurAlgo, 3, Temps.time);

                this.tab[i].Forme.Opacity        = 0.7;
                this.tabIndices[i].Forme.Opacity = 0.7;
                if (this.tab[i].Valeur != val)
                {
                    com.CoordX = this.tab[i].CoordX;
                    this.tab[i].colorChamp(couleurparcours, Brushes.Black, 1);
                    this.tabIndices[i].colorChamp(couleurparcours, Brushes.Black, 0);
                    com.Text = "  " + this.tab[i].Valeur + " est différente de " + val;
                    com.apparaitre(Temps.time);
                    await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                    this.tab[i].colorChamp(couleurFondCase, couleurBordureCase, 1);
                    this.tabIndices[i].colorChamp(couleurFondCase, couleurBordureCase, 0);

                    await algo.colorer(couleurAlgo, 6, Temps.time);

                    i++;
                }
                else
                {
                    tabInfo[0] = 1;
                    comPrincipal.disparaitre(1);
                    comPrincipal.Text = "La valeur " + val + " a été trouvé";
                    await algo.colorer(couleurAlgo, 4, Temps.time);

                    comPrincipal.CouleurFond  = couleurtrouve;
                    this.tab[i].Forme.Opacity = 0.7;
                    comPrincipal.apparaitre(Temps.time);
                    this.tabIndices[i].Forme.Opacity = 0.7;
                    if (insSup == false)
                    {
                        this.tab[i].colorChamp(couleurtrouve, couleurtrouve, 1);
                        this.tabIndices[i].colorChamp(couleurtrouve, couleurtrouve, 0);
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        com.disparaitre(0);
                        // this.tab[i].vibrate(4, 19);
                        await Task.Delay(TimeSpan.FromSeconds(4));
                    }
                    else
                    {
                        this.tab[i].colorChamp(couleurtrouve, couleurtrouve, 1);
                        this.tabIndices[i].colorChamp(couleurtrouve, couleurtrouve, 0);
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        com.disparaitre(0);
                    }
                    tabInfo[1] = i;
                }
            }
            if (tabInfo[0] == 0)
            {
                comPrincipal.disparaitre(2.5);
                comPrincipal.Width       = 200;
                comPrincipal.Text        = "La valeur " + val + " n'a pas été trouvé";
                comPrincipal.CouleurFond = couleurparcours;
                comPrincipal.apparaitre(Temps.time);


                com.disparaitre(0.5);
                com.enleverCanvas(c);
                i--;
            }
            await Task.Delay(TimeSpan.FromSeconds(1.5));

            for (i = 0; i < this.tailleTab; i++)
            {
                this.tab[i].colorChamp(couleurFondCase, couleurBordureCase, 1);
                this.tab[i].Forme.Opacity = 1;
                this.tabIndices[i].colorChamp(Brushes.Transparent, Brushes.Transparent, 0);
                this.tab[i].TextBLock.Foreground = Brushes.Black;
            }
            comPrincipal.disparaitre(0.5);
            com.enleverCanvas(c);
            await algo.colorer(Brushes.Red, 7, 0.5 *Temps.time);

            algo.disparaitre(Alg);
        }
Ejemplo n.º 7
0
        private async Task rechercheDicho(int val, int[] tabInfo, Canvas c, Boolean inserSupp, Commentaire comPrincipal, Canvas Alg)
        //Effectue une recherche dichotomique dans le tableau tab
        // tabInfo[0] correspond au boolean trouv et tabInfo[1] correspond à l'indice de la valeur val si il est trouvée sinon l'indice ou devrait être insérée cette valeur .
        // inserSup est un boolean qui indique si il ya une insertion ou suppression aprés cette recherche
        {
            SolidColorBrush couleurBorneSup  = Brushes.Red;
            SolidColorBrush couleurBorneInf  = Brushes.Blue;
            SolidColorBrush couleurDeCaseMed = Brushes.SeaGreen;
            SolidColorBrush couleurTrouv     = Brushes.Green;
            Algo            algo             = new Algo(2, coordX_Algo, coordY_Algo);

            algo.afficher(Alg);
            int bSup = this.tailleTab - 1, bInf = 0, med = 0, i, e = -5, d = -55;

            Point[] tabDepBSup = new Point[1], tabDepBInf = new Point[1], tabDepMedCase = new Point[1], tabDepBSupInd = new Point[1], tabDepBInfInd = new Point[1], tabDepMedCaseInd = new Point[1];
            await algo.colorer(couleurAlgo, 0, Temps.time);

            await algo.colorer(couleurAlgo, 1, Temps.time);

            await algo.colorer(couleurAlgo, 2, Temps.time);

            tabDepBSup[0]      = new Point();
            tabDepBSup[0].Y    = this.coordY;
            tabDepBInf[0]      = new Point();
            tabDepBInf[0].Y    = this.coordY;
            tabDepMedCase[0]   = new Point();
            tabDepMedCase[0].Y = this.coordY;

            tabDepBSupInd[0]      = new Point();
            tabDepBSupInd[0].Y    = this.coordY + b;
            tabDepBInfInd[0]      = new Point();
            tabDepBInfInd[0].Y    = this.coordY + b;
            tabDepMedCaseInd[0]   = new Point();
            tabDepMedCaseInd[0].Y = this.coordY + b;
            Boolean firstIteration = true;
            Champ   borneSup       = new Champ(this.coordX + widthOfcase * bSup, this.coordY, 1, heightOfcase, widthOfcase, Brushes.Transparent, couleurBorneSup, 6);
            Champ   borneInf       = new Champ(this.coordX + widthOfcase * bInf, this.coordY, 1, heightOfcase, widthOfcase, Brushes.Transparent, couleurBorneInf, 6);
            Champ   medCase        = new Champ();
            Champ   borneSupInd    = new Champ(this.coordX + widthOfcase * bSup + a, this.coordY + b, 2, 25, 25, couleurBorneSup, couleurBorneSup, 1);
            Champ   borneInfInd    = new Champ(this.coordX + widthOfcase * bInf + a, this.coordY + b, 2, 25, 25, couleurBorneInf, couleurBorneInf, 1);
            Champ   medCaseInd     = new Champ();

            borneSup.Forme.Opacity    = 0.7;
            borneInf.Forme.Opacity    = 0.7;
            borneSupInd.Forme.Opacity = 0.5;
            borneInfInd.Forme.Opacity = 0.5;
            borneSup.afficher(c);
            borneInf.afficher(c);
            borneSupInd.afficher(c);
            borneInfInd.afficher(c);
            tabInfo[0] = 0;
            Commentaire comBorneSup = new Commentaire("On positionne la borne supérieure \nà la positon du milieu -1 ", Brushes.Black, tab[bSup].CoordX + e, tab[bSup].CoordY + d, 188, 50, couleurBorneSup, couleurBorneSup);
            Commentaire comBorneInf = new Commentaire("On positionne la borne inférieure \nà la positon du milieu +1 ", Brushes.Black, tab[bInf].CoordX + e, tab[bInf].CoordY + d, 188, 50, couleurBorneInf, couleurBorneInf);
            Commentaire comMed      = new Commentaire("", Brushes.Black, tab[med].CoordX + e, tab[med].CoordY + d, 50, 50, couleurDeCaseMed, couleurDeCaseMed);

            comBorneSup.opacity = 0;
            comBorneInf.opacity = 0;
            comBorneSup.ajouterCanvas(c);
            comBorneInf.ajouterCanvas(c);

            while ((bInf <= bSup) && (tabInfo[0] == 0))
            {
                await algo.colorer(couleurAlgo, 3, Temps.time);

                med           = (bSup + bInf) / 2;
                comMed.Text   = "On positionne le \nmilieu du tableau";
                comMed.Height = 50;
                comMed.Width  = 100;
                comMed.CoordX = this.tab[med].CoordX + e;
                comMed.CoordY = this.tab[med].CoordY + d;
                if (firstIteration)
                {
                    medCase                  = new Champ(this.coordX + widthOfcase * med, this.coordY, 1, heightOfcase, widthOfcase, Brushes.Transparent, couleurDeCaseMed, 6);
                    medCaseInd               = new Champ(this.coordX + widthOfcase * med + a, this.coordY + b, 2, 25, 25, couleurDeCaseMed, couleurDeCaseMed, 1);
                    medCase.Forme.Opacity    = 0.7;
                    medCaseInd.Forme.Opacity = 0.5;
                    medCase.afficher(c);
                    medCaseInd.afficher(c);
                    firstIteration = false;
                    comMed.ajouterCanvas(c);
                    await algo.colorer(couleurAlgo, 4, Champ.time);

                    comMed.disparaitre(Champ.time);
                    await Task.Delay(TimeSpan.FromSeconds(Champ.time + 1));
                }
                else
                {
                    tabDepBSup[0].X       = this.coordX + widthOfcase * bSup;
                    tabDepBInf[0].X       = this.coordX + widthOfcase * bInf;
                    tabDepMedCase[0].X    = this.coordX + widthOfcase * med;
                    tabDepBSupInd[0].X    = this.coordX + widthOfcase * bSup + a;
                    tabDepBInfInd[0].X    = this.coordX + widthOfcase * bInf + a;
                    tabDepMedCaseInd[0].X = this.coordX + widthOfcase * med + a;
                    borneSup.deplacer(tabDepBSup, 1);
                    borneInf.deplacer(tabDepBInf, 1);
                    borneSupInd.deplacer(tabDepBSupInd, 1);
                    borneInfInd.deplacer(tabDepBInfInd, 1);
                    await Task.Delay(TimeSpan.FromSeconds(Champ.time + 1));

                    medCase.deplacer(tabDepMedCase, 1);
                    medCaseInd.deplacer(tabDepMedCaseInd, 1);
                    comMed.apparaitre(Champ.time);
                    await algo.colorer(couleurAlgo, 4, 2 *Temps.time);

                    comMed.disparaitre(Champ.time);
                    await Task.Delay(TimeSpan.FromSeconds(Champ.time + 1));

                    if (bSup != this.tailleTab)
                    {
                        for (i = bSup + 1; i < this.tailleTab; i++)
                        {
                            tab[i].colorChamp(Brushes.Gray, couleurBordureCase, 1);
                            tab[i].Forme.Opacity        = 0.2;
                            tab[i].TextBLock.Foreground = Brushes.Gray;
                        }
                    }
                    if (bInf != 0)
                    {
                        for (i = bInf - 1; i > -1; i--)
                        {
                            tab[i].colorChamp(Brushes.Gray, couleurBordureCase, 1);
                            tab[i].Forme.Opacity        = 0.2;
                            tab[i].TextBLock.Foreground = Brushes.Gray;
                        }
                    }
                    await Task.Delay(TimeSpan.FromSeconds(Temps.time));
                }

                if (tab[med].Valeur == val)
                {
                    tabInfo[0] = 1;
                }
                else
                {
                    await algo.colorer(couleurAlgo, 6, Temps.time);

                    if (tab[med].Valeur > val)
                    {
                        comMed.Text   = val + " est inférieure à la \nvaleur du milieu du tableau";
                        comMed.Height = 50;
                        comMed.Width  = 152;
                        comMed.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 9, 2 *Temps.time + 3);

                        await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1.5));

                        comMed.disparaitre(Temps.time);
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1.5));

                        comBorneSup.CoordX = this.tab[bSup].CoordX + e;
                        comBorneSup.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 10, 2 *Temps.time);

                        comBorneSup.disparaitre(Temps.time);
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time + 2));

                        bSup = med - 1;
                    }
                    else
                    {
                        comMed.Text   = val + " est supérieure à la \nvaleur du milieu du tableau";
                        comMed.Height = 50;
                        comMed.Width  = 152;
                        comMed.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 7, 2 *Temps.time);

                        comMed.disparaitre(Temps.time);
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1));

                        comBorneInf.CoordX = this.tab[bInf].CoordX + e;
                        comBorneInf.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 8, 2 *Temps.time);

                        comBorneInf.disparaitre(Temps.time);
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time + 2));

                        bInf = med + 1;
                    }
                }
            }
            if (tabInfo[0] == 0)
            {
                tabDepBSup[0].X    = this.coordX + widthOfcase * bSup;
                tabDepBInf[0].X    = this.coordX + widthOfcase * bInf;
                tabDepBSupInd[0].X = this.coordX + widthOfcase * bSup + a;
                tabDepBInfInd[0].X = this.coordX + widthOfcase * bInf + a;
                borneSup.deplacer(tabDepBSup, 1);
                borneInf.deplacer(tabDepBInf, 1);
                borneSupInd.deplacer(tabDepBSupInd, 1);
                borneInfInd.deplacer(tabDepBInfInd, 1);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                if (bSup != this.tailleTab)
                {
                    for (i = bSup + 1; i < this.tailleTab; i++)
                    {
                        tab[i].colorChamp(Brushes.Gray, couleurBordureCase, 1);
                        tab[i].Forme.Opacity        = 0.2;
                        tab[i].TextBLock.Foreground = Brushes.Gray;
                    }
                }
                if (bInf != 0)
                {
                    for (i = bInf - 1; i > -1; i--)
                    {
                        tab[i].colorChamp(Brushes.Gray, couleurBordureCase, 1);
                        tab[i].Forme.Opacity        = 0.2;
                        tab[i].TextBLock.Foreground = Brushes.Gray;
                    }
                }
                await Task.Delay(TimeSpan.FromSeconds(0.5));

                tabInfo[1] = bInf;
                comPrincipal.disparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                comPrincipal.Width       = 350;
                comPrincipal.Height      = 50;
                comPrincipal.CouleurFond = Brushes.Red;
                comPrincipal.Text        = "Condition d'arrêt : Borne supérieure < Borne inférieure";
                comPrincipal.apparaitre(Temps.time);
            }
            else
            {
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                await algo.colorer(couleurAlgo, 5, 2 *Temps.time);

                tabInfo[1] = med;
                for (i = 0; i < this.tailleTab; i++)
                {
                    this.tab[i].colorChamp(couleurFondCase, couleurBordureCase, 1);
                    this.tab[i].Forme.Opacity        = 1;
                    this.tab[i].TextBLock.Foreground = Brushes.Black;
                }
                c.Children.Remove(borneSup.Forme);
                c.Children.Remove(borneInf.Forme);
                c.Children.Remove(medCase.Forme);
                c.Children.Remove(borneSupInd.Forme);
                c.Children.Remove(borneInfInd.Forme);
                c.Children.Remove(medCaseInd.Forme);
                comPrincipal.disparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                comPrincipal.CouleurFond = couleurTrouv;
                await Task.Delay(TimeSpan.FromSeconds(0.5));

                comPrincipal.Text = "Valeur " + val + " a été trouvée";
                if (inserSupp)
                {
                    this.tab[med].colorChamp(couleurTrouv, couleurTrouv, 1);
                    this.tab[med].Forme.Opacity = 0.7;
                }
                else
                {
                    this.tab[med].colorChamp(couleurTrouv, couleurTrouv, 1);
                    this.tab[med].Forme.Opacity = 0.7;
                    // this.tab[med].vibrate(2, 19);
                }
                comPrincipal.apparaitre(Temps.time);
            }
            await Task.Delay(TimeSpan.FromSeconds(3));

            for (i = 0; i < this.tailleTab; i++)
            {
                this.tab[i].colorChamp(couleurFondCase, couleurBordureCase, 1);
                this.tab[i].Forme.Opacity        = 1;
                this.tab[i].TextBLock.Foreground = Brushes.Black;
            }
            comPrincipal.disparaitre(0.5);
            c.Children.Remove(borneSup.Forme);
            c.Children.Remove(borneInf.Forme);
            c.Children.Remove(medCase.Forme);
            c.Children.Remove(borneSupInd.Forme);
            c.Children.Remove(borneInfInd.Forme);
            c.Children.Remove(medCaseInd.Forme);
            comBorneInf.enleverCanvas(c);
            comBorneSup.enleverCanvas(c);
            comMed.enleverCanvas(c);
            await algo.colorer(couleurAlgo, 11, Temps.time);

            algo.disparaitre(Alg);
        }
Ejemplo n.º 8
0
        public async Task recherche_seq(int val, int[] tabInfo, Canvas c, Boolean insSup, Commentaire comPrincipal, Canvas Algo)
        {
            //recherche de la valeur val et returne indice qui se trouve dans tabInfo
            int i = 0;

            tabInfo[0] = 0;
            Algo            algo            = new Algo(15, coordX_Algo, coordY_Algo); //Création d'un algorithme de déroulement
            SolidColorBrush couleurparcours = Brushes.Red;
            SolidColorBrush couleurtrouve   = Brushes.Green;
            Commentaire     com             = new Commentaire(" ", Brushes.Black, this.coordX - 5, this.coordY - 35, 50, 50, couleurparcours, couleurparcours);

            comPrincipal.CouleurFond    = Brushes.Yellow;
            comPrincipal.CouleurBordure = Brushes.Black;
            comPrincipal.apparaitre(1);                          //Apparaitre le commentaire principale
            comPrincipal.Text = "Recherche en cours ...";
            algo.afficher(Algo);                                 //Affichage de l'algorithme
            await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time); //Déroulement de l'algorithme

            await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);

            await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

            await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

            com.ajouterCanvas(c);
            com.disparaitre(0);
            com.opacity = 0;
            com.Height  = 30;
            com.Width   = 160;
            Fleche parcours = new Fleche(1);//Création de la fléche de parcourt

            parcours.Height      = tailleFleche;
            parcours.StrokeThick = 3;
            parcours.Color       = couleurparcours;
            parcours.L.Opacity   = 0.9;
            parcours.CoordY      = this.coordY + widthOfmaillon / 2;
            if (this.triee == false)                           //Si la liste n'est pas triée
            {
                while (i < this.list.Count && tabInfo[0] == 0) //Si on est pas arriver à la fin de la liste
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    this.list[i].opacity = 0.7;
                    if (this.list[i].Valeur != val)//Si la valeur du maillon est différente de la valeur rechercher
                    {
                        com.CoordX = this.list[i].CoordX;
                        com.CoordY = this.list[i].CoordY - 35;
                        this.list[i].colorMaillon(couleurparcours, couleurBordureMaillon, 2);//On colorie en gris le maillon
                        this.list[i].colorCase(couleurparcours, couleurBordureMaillon, 2);
                        com.Text = "  " + this.list[i].Valeur + " est différent de " + val;
                        com.apparaitre(Temps.time);//On affiche le commantaire que la valeur du maillon est différente de la valeur rechercher
                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                        parcours.CoordX = list[i].Adr.CoordX;//On passe au coordonnée de la fléche du maillon suivant
                        parcours.bout   = new Bout(list[i].Adr.bout.coordX, list[i].Adr.bout.coordY, couleurparcours, list[i].Adr.bout.TypeBout, 2.5);
                        if (i < list.Count - 1)
                        {
                            await parcours.dessiner(Temps.time, c);                   //On dessine la fléche du partcourt
                        }
                        await algo.colorer(couleurAlgo, 8, Temps.time);

                        parcours.retirerCanvas(c);
                        com.disparaitre(0);
                        this.list[i].colorMaillon(couleurFondMaillon, couleurBordureMaillon, 2); tabInfo[1] = tabInfo[1] + 1;
                        this.list[i].colorCase(couleurFondMaillon, couleurBordureMaillon, 2);
                        await algo.colorer(couleurAlgo, 9, Temps.time);
                    }
                    else//Si on a trouver la valeur
                    {
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        tabInfo[0] = 1;//Indiquer qu'on a trouvé la valeur
                        comPrincipal.disparaitre(1);
                        comPrincipal.Text           = "La valeur " + val + " a été trouvée";
                        comPrincipal.CouleurFond    = couleurtrouve;
                        comPrincipal.CouleurBordure = couleurtrouve;
                        this.list[i].opacity        = 0.7;
                        comPrincipal.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        if (insSup == false)//Si il n'y a pas d'insertion aprés
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                            this.list[i].clignoter(couleurtrouve, couleurtrouve, 2, 3);
                            await Task.Delay(TimeSpan.FromSeconds(4));
                        }
                        else
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                        }
                        await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);
                    }
                    await algo.colorer(couleurAlgo, 10, 0.2 *Temps.time);

                    i++;
                }
                await algo.colorer(couleurAlgo, 11, 0.2 *Temps.time);
            }
            else//Si la liste est triée
            {
                parcours.CoordX = heightOfmaillon + list[i].CoordX;
                while (i < this.list.Count && tabInfo[0] == 0 && list[i].Valeur <= val)//On s'arrete si on arrive à nil ou si on trouve une valeur supérieur à la valeur rechercher
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    this.list[i].opacity = 0.7;
                    if (this.list[i].Valeur != val)
                    {
                        com.CoordX = this.list[i].CoordX;
                        com.CoordY = this.list[i].CoordY - 35;
                        this.list[i].colorMaillon(couleurparcours, couleurBordureMaillon, 2);
                        this.list[i].colorCase(couleurparcours, couleurBordureMaillon, 2);
                        com.Text = "  " + this.list[i].Valeur + " est différent de " + val;
                        com.apparaitre(Temps.time);//faire apparaitre le commentaire
                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                        parcours.CoordX = list[i].Adr.CoordX;
                        parcours.bout   = new Bout(list[i].Adr.bout.coordX, list[i].Adr.bout.coordY, couleurparcours, list[i].Adr.bout.TypeBout, 2.5);
                        if (i < list.Count - 1)
                        {
                            await parcours.dessiner(Temps.time, c);
                        }
                        await algo.colorer(couleurAlgo, 8, Temps.time);

                        com.disparaitre(0);//faire disparaitre le commentaire
                        parcours.retirerCanvas(c);
                        this.list[i].colorMaillon(couleurFondMaillon, couleurBordureMaillon, 2); tabInfo[1] = tabInfo[1] + 1;
                        this.list[i].colorCase(couleurFondMaillon, couleurBordureMaillon, 2);
                    }
                    else//Si on trouver la valeur
                    {
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        tabInfo[0] = 1;
                        comPrincipal.disparaitre(1);
                        comPrincipal.Text           = "La valeur " + val + " a été trouvée";
                        comPrincipal.CouleurFond    = couleurtrouve;
                        comPrincipal.CouleurBordure = couleurtrouve;
                        this.list[i].opacity        = 0.7;
                        comPrincipal.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        if (insSup == false)//si la recherche est suivie d'une insértion/suppression
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);//faire disparaitre le commentaire
                            this.list[i].clignoter(couleurtrouve, couleurtrouve, 2, 4);
                            await Task.Delay(TimeSpan.FromSeconds(4));
                        }
                        else
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);//faire disparaitre le commentaire
                        }
                        await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);
                    }
                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);

                    i++;
                }
                await algo.colorer(couleurAlgo, 11, 0.5 *Temps.time);
            }
            if (tabInfo[0] == 0)//Si on a pas trouvé la valeur
            {
                comPrincipal.disparaitre(2.5);
                comPrincipal.Width          = 200;
                comPrincipal.Text           = "La valeur " + val + " n'a pas été trouvée";
                comPrincipal.CouleurFond    = couleurparcours;
                comPrincipal.CouleurBordure = couleurparcours;
                comPrincipal.apparaitre(Temps.time);
                com.enleverCanvas(c);
                if (!triee)
                {
                    tabInfo[1] = tabInfo[1] - 1;
                }
            }
            comPrincipal.disparaitre(2);
            await algo.colorer(couleurAlgo, 12, Temps.time);

            algo.disparaitre(Algo);           //faire disparaitre l'algorithme déroulant
            foreach (Maillon maillon in list) //Remettre les maillons de la liste en leurs couleurs d'origine
            {
                maillon.colorMaillon(couleurFondMaillon, couleurBordureMaillon, 2);
                maillon.colorCase(couleurFondCase, couleurBordureMaillon, 2);
            }
        }
Ejemplo n.º 9
0
        public async Task insert(int val, Canvas c, Commentaire comPrincipal, Canvas Algo)
        {
            //Insertion de la valeur val dans la liste
            int[] tabInfo = new int[2];
            int   pos     = 0;
            Algo  algo    = new Algo(11, coordX_Algo, coordY_Algo);

            if (list.Count != 0)//Recherche si la valeur existe dans la liste
            {
                await recherche_seq(val, tabInfo, c, true, comPrincipal, Algo);

                await Task.Delay(2000);
            }
            if (tabInfo[0] == 0)//Si la valeur n'existe pas
            {
                comPrincipal.Text           = "Insertion en cours...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Black;
                comPrincipal.apparaitre(0); //faire apparaitre le commentaire
                algo.afficher(Algo);        //faire apparaitre l'algorithme déroulant
                await algo.colorer(couleurAlgo, 0, Temps.time);

                if (this.triee)
                {
                    pos = tabInfo[1];
                }
                Commentaire com = new Commentaire("Insertion au début de la liste", Brushes.Black, coordX + (pos) * (heightOfmaillon + tailleFleche + 5) + 10, coordY - widthOfmaillon, 200, 30, Brushes.PaleTurquoise, Brushes.White);
                if (triee && pos != 0)
                {
                    com.Text = "Insertion à la position : " + pos;
                }
                Point[] tabPoint = new Point[1];
                list.Add(new Maillon());                        //ajouter le maillon dans la liste
                /******Déroulement de l'algorithme******/
                if ((pos == this.list.Count - 1) && (pos != 0)) //insértion en fin de liste
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);
                }
                else if (list.Count - 1 == 0)//insértion en début de liste
                {
                    await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);
                }
                else//insértion au milieu de la liste
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);
                }
                for (int i = list.Count - 2; i >= pos; i--)      //Décalages des maillons pour l'insertion
                {
                    tabPoint[0] = new Point(coordX + (i + 1) * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY);
                    list[i].deplacer(tabPoint, 1);
                    if (i != list.Count - 2)
                    {
                        list[i].Adr.decaler(coordX + (i + 2) * (heightOfmaillon + tailleFleche + 5) - tailleFleche + 5, coordX + (i + 2) * (heightOfmaillon + tailleFleche + 5));
                    }
                    else
                    {
                        list[i].Adr.retirerCanvas(c);
                        list[i].Adr = new Fleche(coordX + (i + 2) * (heightOfmaillon + tailleFleche + 5) - tailleFleche, list[i].Adr.CoordY, list[i].Adr.Color, (list.Count - 1) * (heightOfmaillon + tailleFleche + 5) + heightOfmaillon + 5, 5, 1);
                        list[i].Adr.dessiner(Temps.time, c);
                    }
                    list[i + 1] = list[i];
                }
                if ((pos == this.list.Count - 1) && (pos != 0))//Si le maillon a inséré est à la fin de la liste
                {
                    list[pos] = new Maillon(val, coordX + (pos) * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 5, 1, (list.Count - 1) * (heightOfmaillon + tailleFleche + 5) + heightOfmaillon + 5);
                    list[pos - 1].Adr.retirerCanvas(c);
                    list[pos - 1].Adr = new Fleche(list[pos - 1].CoordX + heightOfmaillon - 5, list[pos - 1].Adr.CoordY, list[pos - 1].Adr.Color, tailleFleche, 1, 1);
                    list[pos - 1].Adr.dessiner(Temps.time, c);
                }
                else if (list.Count - 1 == 0)//Si la liste est vide
                {
                    list[pos] = new Maillon(val, coordX + (pos) * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 5, 1, heightOfmaillon + 5);
                }
                else
                {
                    list[pos] = new Maillon(val, coordX + (pos) * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 1, 1, tailleFleche);
                }
                list[pos].appear(c);                            //faire apparaitre le maillon à insérer
                com.ajouterCanvas(c);                           //ajouter le commentaire
                if ((pos == this.list.Count - 1) && (pos != 0)) //insértion en fin de liste
                {
                    await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);
                }
                else if (list.Count - 1 == 0)//insértion en début de liste
                {
                    await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);
                }
                else//insértion au milieu de la liste
                {
                    await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);
                }
                com.apparaitre(0.5);   // faire apparaitre le commentaire
                com.disparaitre(2000); //faire disparaitre le commentaire
                await Task.Delay(2000);

                await algo.colorer(couleurAlgo, 8, Temps.time);

                com.enleverCanvas(c);
            }
            else//si la valeur a été trouvée dans la liste
            {
                comPrincipal.Text           = "Insertion impossible.\nLa valeur existe déjà";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(0);//faire apparaitre le commentaire
                await Task.Delay(2000);
            }
            comPrincipal.disparaitre(1); //faire disparaitre le commentaire
            algo.disparaitre(Algo);      //faire disparaitre l'algorithme déroulant
        }
Ejemplo n.º 10
0
        public async Task trans(double x, double y, Canvas c, Commentaire comPrincipal, Matrice transposée, Canvas Algo)        //Transposée d'une matrice
        {
            Algo algo = new Algo(29, coordX_Algo, coordY_Algo);

            algo.afficher(Algo);
            Commentaire com1 = new Commentaire("Matrice de type\n" + nbLignes + " x " + nbColonnes.ToString(), Brushes.Black, coordX, coordY - 60, 210, 50, couleurCom, Brushes.White);

            comPrincipal.Text        = "Transposition d'une matrice";
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            com1.ajouterCanvas(c);
            com1.apparaitre(Temps.time);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            Commentaire com2 = new Commentaire("Matrice transposée de type\n" + nbColonnes.ToString() + " x " + nbLignes.ToString(), Brushes.Black, x + nbLignes * widthOfcase + 30, y + heightOfcase, 150, 50, couleurCom, Brushes.White);

            com2.ajouterCanvas(c);
            com2.apparaitre(Temps.time);
            await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time);

            Matrice squelette = new Matrice(nbColonnes, nbLignes, x, y);        //Création d'un corps de la matrice transposée

            for (int i = 0; i < nbColonnes; i++)
            {
                for (int j = 0; j < nbLignes; j++)
                {
                    squelette.tab[i, j] = new Case(0, x + j * widthOfcase, y + i * heightOfcase, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                    squelette.tab[i, j].TextBLock.Opacity = 0;
                }
            }
            squelette.afficher(c);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

            com1.disparaitre(Temps.time);
            com2.disparaitre(Temps.time);
            Point[] tabPoint = new Point[1];
            for (int i = 0; i < nbLignes; i++)
            {
                await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);        //Affichage de l'étape dans l'algo

                if (i != 0)
                {
                    com1.Text = (i + 1).ToString() + "ème ligne";       //Explication de l'étape dans les commentaires
                    com2.Text = (i + 1).ToString() + "ème colonne";
                }
                else
                {
                    com1.Text = (i + 1).ToString() + "ère ligne";
                    com2.Text = (i + 1).ToString() + "ère colonne";
                }
                com1.CoordX = coordX - 100;
                com1.CoordY = coordY + 50 * i + 5;
                com1.Height = 40;
                com1.Width  = 80;
                com1.apparaitre(Temps.time);
                com2.CoordX = x + 50 * i - 20;
                com2.CoordY = y - 50;
                com2.Height = 40;
                com2.Width  = 90;
                com2.apparaitre(Temps.time);
                for (int j = 0; j < nbColonnes; j++)
                {
                    tab[i, j].colorChamp(couleurSelection, couleurBordureCase, 1);                                      //Les lignes la matrice sont les colonnes de la matrice transposée
                }
                for (int j = 0; j < nbColonnes; j++)
                {
                    squelette.tab[j, i].colorChamp(couleurSelection, couleurBordureCase, 1);
                }
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                for (int j = 0; j < nbColonnes; j++)
                {
                    await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

                    //await Task.Delay(50);
                    transposée.tab[j, i] = new Case(tab[i, j].Valeur, coordX + j * widthOfcase, coordY + i * heightOfcase, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                    transposée.tab[j, i].Forme.Opacity = 0;
                    transposée.tab[j, i].afficher(c);
                    tab[i, j].clignoter(couleurClignottement, couleurBordureCase, 1, 2);        //Déplacement de chaque élément de la ligne de la matrice
                    tabPoint[0] = new Point(x + i * widthOfcase, y + j * heightOfcase);         //Vers la colonne de la transposée
                    await transposée.tab[j, i].appear(tabPoint, 1);
                    await Task.Delay(50);

                    transposée.tab[j, i].Forme.Opacity = 1;
                    tab[i, j].colorChamp(couleurSelection, couleurBordureCase, 1);
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);
                }
                for (int j = 0; j < nbColonnes; j++)
                {
                    tab[i, j].colorChamp(couleurFondCase, couleurBordureCase, 1);
                }
                for (int j = 0; j < nbColonnes; j++)
                {
                    squelette.tab[j, i].colorChamp(couleurFondCase, couleurBordureCase, 1);
                }
                await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);
            }
            await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

            com1.disparaitre(Temps.time);
            com2.disparaitre(Temps.time);
            squelette.masquer(c);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

            comPrincipal.Text = "Transposition de la matrice réussie !";
            algo.disparaitre(Algo);
        }
Ejemplo n.º 11
0
        public async Task trieeTransposition(Canvas c, Commentaire comPrincipal, Canvas Alg)
        {
            int             i, j, i1, j1;
            SolidColorBrush couleurPermute    = Brushes.Red;
            SolidColorBrush couleurPermutePas = Brushes.Green;
            Algo            algo = new Algo(4, coordX_Algo, coordY_Algo);

            comPrincipal.Text           = "trie par transposition\n Deux éléments qui se suivent sont comparés puis \npermutés si le 2ième élément est plus petit que le premier,\n(dans ce cas un retour en arrière est effectué afin de vérifier si\nl'ordre n'a pas été modifié, auquel cas on le rétablit). ";
            comPrincipal.CouleurFond    = couleurComPrincipal;
            comPrincipal.CouleurBordure = Brushes.Black;
            comPrincipal.Width          = 340;
            comPrincipal.Height         = 100;
            comPrincipal.apparaitre(0);
            algo.afficher(Alg);
            await algo.colorer(couleurAlgo, 0, Temps.time);

            Commentaire com = new Commentaire("", Brushes.Black, coordX, coordY + 100, 120, 50, couleurPermute, couleurPermute);

            com.ajouterCanvas(c);
            com.opacity = 0;
            for (i = 0; i < this.tailleTab - 1; i++)
            {
                j = i;
                await algo.colorer(couleurAlgo, 1, Temps.time);

                await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

                while ((j >= 0) && (tab[j].Valeur > tab[j + 1].Valeur))
                {
                    permuterDeuxCase(j, j + 1, couleurPermute, couleurPermute);
                    i1                 = j + 1;
                    j1                 = j + 2;
                    com.Text           = "On permute \n" + "les cases : " + i1 + " et " + j1;
                    com.CouleurFond    = couleurPermute;
                    com.CouleurBordure = couleurPermute;
                    com.apparaitre(Temps.time);
                    if (i == j)
                    {
                        await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);
                    }
                    else
                    {
                        await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);
                    }
                    await Task.Delay((TimeSpan.FromSeconds(Temps.time * 3)));

                    com.disparaitre(Temps.time / 2);
                    tab[j].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                    tab[j + 1].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                    j = j - 1;
                }
                await algo.colorer(couleurAlgo, 9, Temps.time);

                if (j != tailleTab - 2 && tab[j + 1].Valeur <= tab[j + 2].Valeur)
                {
                    com.Text           = "On permute pas ";
                    com.CouleurFond    = couleurPermutePas;
                    com.CouleurBordure = couleurPermutePas;

                    if (j != -1)
                    {
                        tab[j].colorChamp(couleurPermutePas, couleurBordureCase, 1);
                        tab[j + 1].colorChamp(couleurPermutePas, couleurBordureCase, 1);


                        com.apparaitre(Temps.time);
                        await Task.Delay((TimeSpan.FromSeconds(Temps.time * 3)));

                        com.disparaitre(Temps.time / 2);

                        tab[j].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                        tab[j + 1].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                    }
                }
            }
            await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);

            await algo.colorer(couleurAlgo, 11, 0.5 *Temps.time);

            algo.disparaitre(Alg);
            comPrincipal.disparaitre(0);
        }
Ejemplo n.º 12
0
        public async Task insert(int val, Canvas c, Commentaire comPrincipal, Canvas Alg)
        {
            int[] tabInfo = new int[2];
            int   pos     = 0;
            Algo  algo    = new Algo(13, coordX_Algo, coordY_Algo);

            if (list.Count != 0)
            {
                await recherche_seq(val, tabInfo, c, true, comPrincipal, Alg); //recherche de la valeur dans la liste
            }
            if (tabInfo[0] == 0)                                               //si la valeur n'existe pas dans la liste
            {
                comPrincipal.Text           = "Insertion en cours...";
                comPrincipal.CouleurFond    = Brushes.Yellow;
                comPrincipal.CouleurBordure = Brushes.Black;
                comPrincipal.apparaitre(0); // faire apparaitre le commentaire
                algo.afficher(Alg);         // faire apparaitre l'algorithme déroulant
                await algo.colorer(couleurAlgo, 0, Temps.time);

                if (this.triee)
                {
                    pos = tabInfo[1];
                }
                Commentaire com = new Commentaire("Insertion à la tête de la liste", Brushes.Black, coordX + (pos) * (heightOfmaillon + tailleFleche + 5) + 10, coordY - widthOfmaillon, 200, 30, Brushes.PaleTurquoise, Brushes.White);
                if (triee && pos != 0)
                {
                    com.Text = "Insertion à la position : " + pos;
                }
                Point[] tabPoint = new Point[1];
                list.Add(new Maillon_bi()); //ajouter le maillon dans la liste
                if (list.Count - 1 == 0)    //si la liste est vide
                {
                    await algo.colorer(couleurAlgo, 1, Temps.time);

                    await algo.colorer(couleurAlgo, 2, Temps.time);
                }
                else if (pos == 0)//insértion à la première position
                {
                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);
                }
                else if (pos == this.list.Count - 1)//insértion à la dernière position
                {
                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);
                }
                else//insértion au milieu de la liste
                {
                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);
                }
                for (int i = list.Count - 1; i > pos; i--)//décalage des maillon pour l'insértion
                {
                    tabPoint[0] = new Point(coordX + i * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY);
                    list[i - 1].deplacer(tabPoint, 1);
                    list[i - 1].Adr.decaler(tabPoint[0].X + heightOfmaillon - 5, tabPoint[0].X + heightOfmaillon + tailleFleche - 5);
                    list[i - 1].Prec.decaler(tabPoint[0].X + 5, tabPoint[0].X - tailleFleche + 5);
                    list[i] = list[i - 1];
                }
                if (list.Count - 1 == 0)//liste vide
                {
                    list[0] = new Maillon_bi(val, coordX + tailleFleche, coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 3, 3, tailleFleche);
                }
                else if (pos == 0)//insértion en début de liste
                {
                    list[pos] = new Maillon_bi(val, coordX + (pos) * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 3, 1, tailleFleche);
                    list[1].Prec.retirerCanvas(c);
                    list[1].Prec = new Fleche(list[0].Adr.CoordX + tailleFleche + 10, list[1].Prec.CoordY, list[1].Prec.Color, tailleFleche, 2, 2);
                }
                else if (pos == this.list.Count - 1)//insértion en fin de liste
                {
                    list[pos] = new Maillon_bi(val, coordX + (pos) * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 2, 3, tailleFleche);
                    list[pos - 1].Adr.retirerCanvas(c);
                    list[pos - 1].Adr = new Fleche(list[pos - 1].CoordX + heightOfmaillon - 5, list[pos - 1].Adr.CoordY, list[pos - 1].Adr.Color, tailleFleche, 1, 1);
                    await list[pos - 1].Adr.dessiner(Temps.time, c);
                }
                else//insértion au milieu
                {
                    list[pos] = new Maillon_bi(val, coordX + (pos) * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 2, 1, tailleFleche);
                }
                list[pos].appear(c);//faire apparaitre le maillon à insérer
                if (list.Count - 1 != 0 && pos == 0)
                {
                    await list[1].Prec.dessiner(Temps.time, c);
                }
                com.ajouterCanvas(c);
                com.apparaitre(0.5);     //faire apparaitre le commentaire
                if (list.Count - 1 == 0) //liste vide
                {
                    await algo.colorer(couleurAlgo, 3, Temps.time);

                    await algo.colorer(couleurAlgo, 4, Temps.time);
                }
                else if (pos == 0)//insértion en début de liste
                {
                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);
                }
                else if (pos == this.list.Count - 1)//insértion en fin de liste
                {
                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);
                }
                else//insértion au milieu de la liste
                {
                    await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);
                }
                com.disparaitre(2000);//faire disparaitre le commentaire
                await Task.Delay(2000);

                await algo.colorer(couleurAlgo, 11, Temps.time);

                com.enleverCanvas(c);//faire disparaitre le commentaire
            }
            else//si la valeur a été trouvée dans la liste
            {
                comPrincipal.Text           = "Insertion impossible.\nLa valeur existe déjà";
                comPrincipal.CouleurFond    = Brushes.Red;
                comPrincipal.CouleurBordure = Brushes.Red;
                comPrincipal.apparaitre(0);// faire apparaitre le commentaire
                await Task.Delay(2000);
            }
            comPrincipal.disparaitre(1); //faire disparaitre le commentaire
            algo.disparaitre(Alg);       //faire disparaitre l'algorithme déroulant
        }
Ejemplo n.º 13
0
        public async Task recherche_seq_qeue(int val, int[] tabInfo, Canvas c, Boolean insSup, Commentaire comPrincipal, Canvas Alg)
        {
            //recherche de la valeur val et returne indice qui se trouve dans tabInfo
            int i = list.Count - 1;

            tabInfo[0] = 0;
            Algo            algo            = new Algo(12, coordX_Algo, coordY_Algo); //Création d'un algorithme de déroulement
            SolidColorBrush couleurparcours = Brushes.Red;
            SolidColorBrush couleurtrouve   = Brushes.Green;
            Commentaire     com             = new Commentaire(" ", Brushes.Black, this.coordX - 5, this.coordY - 35, 50, 50, couleurparcours, couleurparcours);

            comPrincipal.CouleurFond    = Brushes.Yellow;
            comPrincipal.CouleurBordure = Brushes.Black;
            comPrincipal.apparaitre(1);
            comPrincipal.Text = "Recherche en cours ...";
            algo.afficher(Alg);                                  //Affichage de l'algorithme
            await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time); //Déroulement de l'algorithme

            await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);

            await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

            await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

            com.ajouterCanvas(c);
            com.disparaitre(0);
            com.opacity = 0;
            com.Height  = 30;
            com.Width   = 160;
            Fleche parcours = new Fleche(1);

            parcours.Height      = -tailleFleche;
            parcours.StrokeThick = 3;
            parcours.Color       = couleurparcours;
            parcours.L.Opacity   = 0.9;
            parcours.CoordY      = this.coordY + 2 * widthOfmaillon / 3;
            if (this.triee == false)             //Si la liste n'est pas triée
            {
                while (i >= 0 & tabInfo[0] == 0) //Si on est pas arriver à la fin de la liste
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    this.list[i].opacity = 0.7;
                    if (this.list[i].Valeur != val)//Si la valeur du maillon est différente de la valeur rechercher
                    {
                        com.CoordX = this.list[i].CoordX;
                        com.CoordY = this.list[i].CoordY - 35;
                        this.list[i].colorMaillon(couleurparcours, couleurBordureMaillon, 2);//On colorie en gris le maillon
                        this.list[i].colorCase(couleurparcours, couleurBordureMaillon, 2);
                        com.Text = "  " + this.list[i].Valeur + " est différent de " + val;
                        com.apparaitre(Temps.time);//On affiche le commantaire que la valeur du maillon est différente de la valeur rechercher
                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                        parcours.CoordX = list[i].Prec.CoordX;
                        parcours.bout   = new Bout(list[i].Prec.bout.coordX, list[i].Prec.bout.coordY, couleurparcours, list[i].Prec.bout.TypeBout, 2.5);
                        await parcours.dessiner(Temps.time, c);

                        await algo.colorer(couleurAlgo, 8, Temps.time);

                        parcours.retirerCanvas(c);
                        com.disparaitre(0);
                        this.list[i].colorMaillon(Brushes.Gainsboro, couleurBordureMaillon, 2); tabInfo[1] = tabInfo[1] + 1;
                        this.list[i].colorCase(Brushes.Gainsboro, couleurBordureMaillon, 2);
                    }
                    else//Si on a trouver la valeur
                    {
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        tabInfo[0] = 1;
                        comPrincipal.disparaitre(1);
                        comPrincipal.Text           = "La valeur " + val + " a été trouvée";
                        comPrincipal.CouleurFond    = couleurtrouve;
                        comPrincipal.CouleurBordure = couleurtrouve;
                        this.list[i].opacity        = 0.7;
                        comPrincipal.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        if (insSup == false)
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                            // this.list[i].vibrate(4, 19);
                            this.list[i].clignoter(couleurtrouve, couleurtrouve, 2, 3);
                            await Task.Delay(TimeSpan.FromSeconds(4));
                        }
                        else
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                        }
                        await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);
                    }
                    i--;
                    await algo.colorer(couleurAlgo, 10, 0.2 *Temps.time);
                }
                await algo.colorer(couleurAlgo, 11, 0.2 *Temps.time);
            }
            else
            {
                parcours.CoordX = heightOfmaillon + list[i].CoordX;
                while (i >= 0 && tabInfo[0] == 0 && list[i].Valeur >= val)
                {
                    await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                    this.list[i].opacity = 0.7;
                    if (this.list[i].Valeur != val)
                    {
                        com.CoordX = this.list[i].CoordX;
                        com.CoordY = this.list[i].CoordY - 35;
                        this.list[i].colorMaillon(couleurparcours, couleurBordureMaillon, 2);
                        this.list[i].colorCase(couleurparcours, couleurBordureMaillon, 2);
                        com.Text = "  " + this.list[i].Valeur + " est différent de " + val;
                        com.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                        parcours.CoordX = list[i].Prec.CoordX;
                        parcours.bout   = new Bout(list[i].Prec.bout.coordX, list[i].Prec.bout.coordY, couleurparcours, list[i].Prec.bout.TypeBout, 2.5);
                        await parcours.dessiner(Temps.time, c);

                        await algo.colorer(couleurAlgo, 8, Temps.time);

                        parcours.retirerCanvas(c);
                        com.disparaitre(0);
                        this.list[i].colorMaillon(Brushes.Gainsboro, couleurBordureMaillon, 2); tabInfo[1] = tabInfo[1] + 1;
                        this.list[i].colorMaillon(Brushes.Gainsboro, couleurBordureMaillon, 2);
                    }
                    else//Si on trouver la valeur
                    {
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        tabInfo[0] = 1;
                        comPrincipal.disparaitre(1);
                        comPrincipal.Text           = "La valeur " + val + " a été trouvée";
                        comPrincipal.CouleurFond    = couleurtrouve;
                        comPrincipal.CouleurBordure = couleurtrouve;
                        this.list[i].opacity        = 0.7;
                        comPrincipal.apparaitre(Temps.time);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        if (insSup == false)//si la recherche n'est pas suivie d'une insértion/suppression
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                            this.list[i].clignoter(couleurtrouve, couleurtrouve, 2, 3);
                            await Task.Delay(TimeSpan.FromSeconds(4));
                        }
                        else
                        {
                            this.list[i].colorMaillon(couleurtrouve, couleurtrouve, 2);
                            this.list[i].colorCase(couleurtrouve, couleurtrouve, 2);
                            com.disparaitre(0);
                        }
                        await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);
                    }
                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time);

                    i--;
                }
                await algo.colorer(couleurAlgo, 11, 0.5 *Temps.time);
            }
            if (tabInfo[0] == 0)
            {
                comPrincipal.disparaitre(2.5);// faire disparaitre le commentaire
                comPrincipal.Text           = "La valeur " + val + " n'a pas été trouvée";
                comPrincipal.CouleurFond    = couleurparcours;
                comPrincipal.CouleurBordure = couleurparcours;
                comPrincipal.apparaitre(Temps.time);//apparition du commentaire
                com.enleverCanvas(c);
                if (!triee)
                {
                    tabInfo[1] = tabInfo[1] + 1;        //si la liste n'est pas triée
                }
            }
            comPrincipal.disparaitre(2);//faire disparaitre le commentaire
            await algo.colorer(couleurAlgo, 12, Temps.time);

            algo.disparaitre(Alg);//faire disparaitre l'algorithme déroulant
            foreach (Maillon maillon in list)
            {
                maillon.colorMaillon(couleurFondMaillon, couleurBordureMaillon, 2);
                maillon.colorCase(couleurFondCase, couleurBordureMaillon, 2);
            }
        }
Ejemplo n.º 14
0
        private async void detMat2(Case det, Canvas c, Commentaire comPrincipal, Canvas Algo)       //Déterminant d'une matrice 2x2
        {
            Algo algo = new Algo(31, coordX_Algo, coordY_Algo);

            algo.afficher(Algo);
            comPrincipal.Text        = "Calcul de déterminant d'une matrice 2x2...";
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            await algo.colorer(couleurAlgo, 0, Temps.time);

            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            TextBlock textBlock = new TextBlock();

            textBlock.FontFamily = new FontFamily("Poiret One");
            textBlock.Foreground = Brushes.Blue;
            textBlock.FontSize   = 15;
            Canvas.SetLeft(textBlock, coordX);
            Canvas.SetTop(textBlock, coordY + (nbLignes + 0.5) * heightOfcase);
            c.Children.Add(textBlock);


            await algo.colorer(couleurAlgo, 1, Temps.time);     //Clignottement des valeurs de la diagonale (sens positif)

            tab[0, 0].BackgroundColor = couleurSelection;       //et calcul du déterminant avec illustration dans le textblock
            tab[1, 1].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text = "(" + tab[0, 0].Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].BackgroundColor = couleurSelection;
            await Task.Delay(50);

            tab[1, 1].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text           += " x " + tab[1, 1].Valeur + ")";
            tab[1, 1].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 0].BackgroundColor = couleurFondCase;
            tab[1, 1].BackgroundColor = couleurFondCase;
            textBlock.Text           += " - (";

            tab[0, 1].BackgroundColor = couleurSelection;       //Clignottement des valeurs de la diagonale (sens négatif)
            tab[1, 0].BackgroundColor = couleurSelection;       //et calcul du déterminant avec illustration dans le textblock
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text += tab[0, 1].Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].BackgroundColor = couleurSelection;
            await Task.Delay(50);

            tab[1, 0].clignoter(couleurClignottement, couleurBordureCase, 1, 2);
            textBlock.Text           += " x " + tab[1, 0].Valeur + ")";
            tab[1, 0].BackgroundColor = couleurSelection;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            tab[0, 1].BackgroundColor = couleurFondCase;
            tab[1, 0].BackgroundColor = couleurFondCase;

            det.Valeur        = tab[0, 0].Valeur * tab[1, 1].Valeur - tab[1, 0].Valeur * tab[0, 1].Valeur; //Mise en forme de la case contenant le determinant
            det.Height        = heightOfcase * 0.5;
            det.Width         = widthOfcase * 2;
            det.CoordX        = coordX;
            det.CoordY        = coordY + (nbLignes + 0.5) * heightOfcase;
            det.Forme.Opacity = 0;
            det.afficher(c);
            textBlock.Text = "";
            Point[] tabPoint = new Point[1];
            tabPoint[0] = new Point(coordX, coordY + (nbLignes + 0.5) * heightOfcase);
            await det.appear(tabPoint, 1);      //Déplacement du déterminant sous la matrice

            await Task.Delay(50);

            det.Forme.Opacity = 1;
            det.clignoter(Brushes.LightSkyBlue, Brushes.White, 1, 2);      //Clignottement du résultat
            comPrincipal.Text = "Le déterminant de la matrice est " + det.Valeur;
            await algo.colorer(couleurAlgo, 2, Temps.time);

            algo.disparaitre(Algo);
        }
Ejemplo n.º 15
0
        private async void sarus(Case det, Canvas c, Commentaire comPrincipal, Canvas Algo) //Déterminant par la méthode de Sarus
        {
            Algo algo = new Algo(30, coordX_Algo, coordY_Algo);                             //Affichage de l'étape en cours dans l'algo

            algo.afficher(Algo);
            comPrincipal.Text        = "Calcul de déterminant d'une matrice 3x3\npar la méthode de Sarus...";
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            Commentaire[] com = new Commentaire[8];
            await algo.colorer(couleurAlgo, 0, Temps.time);

            for (int i = 0; i < 3; i++)     //Affichage des commentaires d'illustration
            {
                com[i] = new Commentaire("c" + (i + 1), Brushes.Black, coordX + (i + 0.25) * widthOfcase, coordY - 30, 25, 25, couleurCom, couleurCom);
                com[i].ajouterCanvas(c);
                com[i].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            Matrice plus = new Matrice(nbLignes, nbColonnes + 2, coordX + (nbColonnes + 1) * widthOfcase, coordY); //Création d'une matrice 3x5 contentant

            for (int i = 0; i < plus.nbLignes; i++)                                                                //les colonnes c1, c2, c3, c1, c2
            {
                for (int j = 0; j < nbColonnes + 2; j++)
                {
                    plus.tab[i, j] = new Case(tab[i, j % nbColonnes].Valeur, plus.coordX + j * widthOfcase, plus.coordY + i * heightOfcase, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                }
            }
            plus.afficher(c);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time)); //Affichage des commentaires d'illustration

            for (int i = 0; i < 3; i++)
            {
                com[i + 3] = new Commentaire("c" + (i + 1), Brushes.Black, plus.coordX + (i + 0.25) * widthOfcase, plus.coordY - 30, 25, 25, couleurCom, couleurCom);
                com[i + 3].ajouterCanvas(c);
                com[i + 3].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            for (int i = 0; i < 2; i++)
            {
                com[i + 6] = new Commentaire("c" + (i + 1), Brushes.Black, plus.coordX + (i + 3 + 0.25) * widthOfcase, plus.coordY - 30, 25, 25, Brushes.LightPink, Brushes.White);
                com[i + 6].ajouterCanvas(c);
                com[i + 6].apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));
            }
            TextBlock textBlock = new TextBlock();      //Textblock pour affichier l'opération en cours

            textBlock.FontFamily = new FontFamily("Poiret One");
            textBlock.Foreground = Brushes.Blue;
            Canvas.SetLeft(textBlock, coordX);
            Canvas.SetTop(textBlock, plus.coordY + (nbLignes + 1) * heightOfcase);
            c.Children.Add(textBlock);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            int b = 1;

            for (int i = 0; i < 3; i++)     //Parcours des diagonales de gauche à droite (sens positif)
            {
                int j;
                b = 1;
                await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);        //Affichage de l'étape en cours dans l'algo

                await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);

                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, j + i].BackgroundColor = couleurSelection;
                }
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                for (j = 0; j < 3; j++)     //Cases de la diagonale
                {
                    await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

                    plus.tab[j, j + i].clignoter(couleurClignottement, plus.couleurBordureCase, plus.tab[j, j + i].BorderThick, 2); //clignottement de la case
                    textBlock.FontSize = 15;                                                                                        //Et affichage de l'opération dans le textBlock
                    if (j != 0 && j != 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, j + i].Valeur.ToString();
                    }
                    else if (j != 0 && j == 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, j + i].Valeur.ToString() + ")";
                    }
                    else if (i != 0)
                    {
                        textBlock.Text += plus.tab[j, j + i].Valeur.ToString();
                    }
                    else if (i == 0)
                    {
                        textBlock.Text = "(" + plus.tab[j, j + i].Valeur.ToString();
                    }
                    await algo.colorer(couleurAlgo, 4, Temps.time);     //étape en cours dans l'algo

                    if (i != 2 && j == 2)
                    {
                        textBlock.Text += " + (";
                    }
                    plus.tab[j, j + i].colorChamp(couleurSelection, plus.couleurBordureCase, 1);
                    b = b * plus.tab[j, j + i].Valeur;
                    await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);
                }
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, j + i].BackgroundColor = couleurFondCase;
                }
                await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                det.Valeur += b;
                await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);
            }
            for (int i = 4; i > 1; i--)                              //Parcours des diagonales de droite à gauche (sens négatif)
            {
                await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time); //Étapes de l'algo en cours

                await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                int j;
                b = 1;
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, i - j].BackgroundColor = couleurSelection;      //illustration avec couleurs
                }
                textBlock.Text += " - (";
                await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                for (j = 0; j < 3; j++)                                   //Parcours des cases de la diagonale
                {
                    await algo.colorer(couleurAlgo, 10, 0.5 *Temps.time); //Affichage de l'étape en cours dans l'algo

                    plus.tab[j, i - j].clignoter(couleurClignottement, plus.couleurBordureCase, plus.tab[j, i - j].BorderThick, 2);
                    textBlock.FontSize = 15;
                    if (j != 0 && j != 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, i - j].Valeur.ToString();
                    }
                    else if (j != 0 && j == 2)
                    {
                        textBlock.Text += " x " + plus.tab[j, i - j].Valeur.ToString() + ")";
                    }
                    else
                    {
                        textBlock.Text += /*" - (" +*/ plus.tab[j, i - j].Valeur.ToString();
                    }
                    await algo.colorer(couleurAlgo, 11, Temps.time);

                    plus.tab[j, i - j].colorChamp(couleurSelection, plus.couleurBordureCase, 1);
                    b = b * plus.tab[j, i - j].Valeur;
                    await algo.colorer(couleurAlgo, 12, 0.5 *Temps.time);
                }
                for (j = 0; j < 3; j++)
                {
                    plus.tab[j, i - j].BackgroundColor = couleurFondCase;
                }
                await algo.colorer(couleurAlgo, 13, 0.5 *Temps.time);

                await algo.colorer(couleurAlgo, 14, 0.5 *Temps.time);

                det.Valeur -= b;
            }
            det.Height        = heightOfcase * 0.5; //Mise en forme de la case contenant le déterminant
            det.Width         = widthOfcase * 2;
            det.CoordX        = coordX + 3 * widthOfcase;
            det.CoordY        = plus.coordY + (nbLignes + 1) * heightOfcase;
            det.Forme.Opacity = 0;
            det.afficher(c);
            textBlock.Text = "";
            Point[] tabPoint = new Point[1];
            tabPoint[0] = new Point(coordX + widthOfcase / 2, coordY + (nbLignes + 0.5) * heightOfcase);
            await det.appear(tabPoint, 1);          //Affichage du déterminant sous la matrice

            await Task.Delay(50);

            det.Forme.Opacity = 1;
            det.clignoter(Brushes.LightSkyBlue, Brushes.White, 1, 2);
            for (int i = 0; i < 8; i++)
            {
                com[i].disparaitre(Temps.time);
            }
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            for (int i = 0; i < 8; i++)
            {
                com[i].enleverCanvas(c);
            }
            comPrincipal.Text = "Le déterminant de la matrice est " + det.Valeur;
            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

            plus.masquer(c);
            await algo.colorer(couleurAlgo, 15, 0.5 *Temps.time);

            algo.disparaitre(Algo);
        }
Ejemplo n.º 16
0
        public async Task inserer(int valeur, Canvas c, Commentaire comPrincipal, Canvas Alg)
        //Insetion d'un nouvel élément dans le tableau //
        {
            int[]       tabInfo     = new int[2];
            Point[]     tab_point   = new Point[2];
            Commentaire comDecalage = new Commentaire("On décale les valeurs pour l'insertion ", Brushes.Black, this.coordX + 50, this.coordY - 50, 210, 30, Brushes.GreenYellow, Brushes.White);
            Algo        algo        = new Algo(6, coordX_Algo, coordY_Algo);
            Algo        algo1       = new Algo(27, coordX_Algo, coordY_Algo);
            int         pos;//Position d'insertion
            int         i = tailleTab;

            comPrincipal.disparaitre(0);
            if (i < tailleMaxTab)
            {
                Case nouvelleCase = new Case(valeur, coordX, this.coordY - 100, 1, heightOfcase, widthOfcase, couleurFondCase, couleurBordureCase, 1);
                if (tailleTab > 0)                                                //Si il exite au moins une case
                {
                    await recherche(valeur, tabInfo, c, true, comPrincipal, Alg); //Recherche Dichothomique de la valeur

                    comPrincipal.disparaitre(0);
                }
                if (tabInfo[0] == 0) //Si la valeur n'existe pas
                {
                    pos = tabInfo[1];
                    tabIndices[tailleTab].afficher(c); //Afficher le nouvel indice
                    nouvelleCase.afficher(c);          //Affichage de la nouvelle case crée
                    if (this.triee)
                    {
                        algo.afficher(Alg);
                        await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time);

                        await algo.colorer(couleurAlgo, 1, Temps.time);

                        comDecalage.ajouterCanvas(c);          //Affichage du message d'insertion
                        for (i = this.tailleTab; i > pos; i--) //Décalage des cases pour insérer la nouvelle valeur
                        {
                            await algo.colorer(couleurAlgo, 2, Temps.time);

                            tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                            tab[i]       = tab[i - 1];         //Décalage interne des cases du tableau
                            tab[i - 1].deplacer(tab_point, 1); //Décalage graphique des cases du tableau
                            await algo.colorer(couleurAlgo, 3, Temps.time);

                            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                            await algo.colorer(couleurAlgo, 4, Temps.time);
                        }
                        await algo.colorer(couleurAlgo, 5, Temps.time);

                        comDecalage.enleverCanvas(c);
                        tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                        tab[i]       = nouvelleCase;
                        tab[i].deplacer(tab_point, 1);//Insértion graphique de la case
                        comPrincipal.Width       = 200;
                        comPrincipal.CouleurFond = couleurComPrincipal;
                        comPrincipal.Text        = "Insertion de la valeur ";
                        comPrincipal.apparaitre(0);
                        await algo.colorer(couleurAlgo, 6, Temps.time);

                        comPrincipal.disparaitre(0);
                        await algo.colorer(couleurAlgo, 7, Temps.time);

                        await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);

                        this.tailleTab++;//Incrémentation de la taille du tableau
                        algo.disparaitre(Alg);
                    }
                    else
                    {
                        algo1.afficher(Alg);
                        tab_point[0] = new Point(coordX + i * widthOfcase, coordY);
                        tab[i]       = nouvelleCase;
                        tab[i].deplacer(tab_point, 1);//Insértion graphique de la case
                        comPrincipal.Width       = 200;
                        comPrincipal.CouleurFond = couleurComPrincipal;
                        comPrincipal.Text        = "Insertion de la valeur ";
                        comPrincipal.apparaitre(0);
                        comPrincipal.disparaitre(0);
                        this.tailleTab++;//Incrémentation de la taille du tableau
                        algo1.disparaitre(Alg);
                    }
                }
                else
                {
                    comPrincipal.CouleurFond = couleurComPrincipal;
                    comPrincipal.Text        = "Insertion impossible , la valeur existe déja ";
                    comPrincipal.Width       = 320;
                    comPrincipal.apparaitre(0);
                    await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1));

                    comPrincipal.disparaitre(0);
                }
            }
            else
            {
                comPrincipal.CouleurFond = couleurComPrincipal;
                comPrincipal.Text        = "Insertion impossible , taille du tableau maximum atteinte ";
                comPrincipal.Width       = 320;
                comPrincipal.apparaitre(0);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time + 1));

                comPrincipal.disparaitre(0);
            }
        }
Ejemplo n.º 17
0
        public async Task trieeSelection(Canvas c, Commentaire comPrincipal, Canvas Alg)
        {
            int i, j, i1, j1;

            SolidColorBrush couleurPermute        = Brushes.Red;
            SolidColorBrush couleurPermutePas     = Brushes.Green;
            SolidColorBrush couleurCaseAleurPlace = Brushes.LightGreen;

            comPrincipal.Text           = "trie par selection\nPrincipe: Le plus petit élément du tableau est permuté avec\n le 1er élément du tableau,\n puis le plus petit élément du tableau restant\n est permuté avec le 2ième,\n etc...  ";
            comPrincipal.CouleurFond    = couleurComPrincipal;
            comPrincipal.CouleurBordure = Brushes.Black;
            comPrincipal.Width          = 340;
            comPrincipal.Height         = 110;
            comPrincipal.apparaitre(0);
            Algo        algo = new Algo(3, coordX_Algo, coordY_Algo);
            Commentaire com  = new Commentaire("", Brushes.Black, coordX, coordY + 100, 260, 50, couleurPermute, couleurPermute);

            com.ajouterCanvas(c);
            com.opacity = 0;
            algo.afficher(Alg);
            await algo.colorer(couleurAlgo, 0, Temps.time);

            Commentaire com2 = new Commentaire("", Brushes.Black, coordX, coordY - 60, 140, 50, couleurPermutePas, couleurPermutePas);

            com2.ajouterCanvas(c);
            com2.opacity = 0;

            for (i = 0; i < this.tailleTab; i++)
            {
                await algo.colorer(couleurAlgo, 1, Temps.time);

                j = indcinePlusPetit(i, this.tailleTab - 1);

                tab[j].colorChamp(couleurFondCase, Brushes.Green, 4);

                com2.Text   = "le plus petit element \ndans le tableau restant.  ";
                com2.CoordX = widthOfcase * (j + 1);

                com2.CouleurFond    = couleurPermutePas;
                com2.CouleurBordure = couleurPermutePas;

                com2.apparaitre(Temps.time);
                await algo.colorer(couleurAlgo, 2, Temps.time);

                com2.disparaitre(Temps.time / 2);

                await Task.Delay((TimeSpan.FromSeconds(Temps.time * 3)));

                tab[j].colorChamp(couleurFondCase, couleurBordureCase, 1);
                await algo.colorer(couleurAlgo, 3, Temps.time);

                permuterDeuxCase(i, j, couleurPermute, couleurPermute);

                i1 = i + 1;
                j1 = j + 1;

                if (i == j)
                {
                    com.Text  = "On permute pas ";
                    com.Width = 100;


                    com.CouleurFond    = couleurPermutePas;
                    com.CouleurBordure = couleurPermutePas;
                }
                else
                {
                    com.Text           = " le plus petit element dans le tableau est : " + tab[j].Valeur + ".\n On permute " + "les cases : " + i1 + " et " + j1;
                    com.Width          = 260;
                    com.CouleurFond    = couleurPermute;
                    com.CouleurBordure = couleurPermute;
                }

                com.apparaitre(Temps.time);
                await Task.Delay((TimeSpan.FromSeconds(Temps.time * 3)));

                com.disparaitre(Temps.time / 2);


                tab[j].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                tab[i].colorChamp(couleurCaseAleurPlace, couleurPermutePas, 1);
            }
            for (i = 0; i < TailleTab; i++)
            {
                tab[i].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
            }
            comPrincipal.disparaitre(0);
            await algo.colorer(couleurAlgo, 4, Temps.time);

            await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

            algo.disparaitre(Alg);
        }
Ejemplo n.º 18
0
        public async Task suppression(int valeur, Canvas c, Commentaire comPrincipal, Canvas Algo)
        {
            int[]       tabInfo = new int[2]; //Le tableau qui sera modifié par la fonction de recherche
            Commentaire com     = new Commentaire(" ", Brushes.Black, this.coordX - 100, this.coordY - 70, 250, 40, Brushes.BurlyWood, Brushes.White);

            com.ajouterCanvas(c);
            com.opacity = 0;
            Algo algo = new Algo(16, coordX_Algo, coordY_Algo); //instanciation de l'algorithme déroulant

            if (this.list.Count <= 0)                           //si la liste est vide
            {
                com.Text        = "Suppression impossible, la liste est vide !";
                com.CouleurFond = Brushes.Red;
                com.Width       = 250;
                com.Height      = 50;
                com.CoordX      = this.coordX;
                com.CoordY      = this.coordY - 50;
                com.apparaitre(Temps.time);//faire apparaitre le commentaire
                await Task.Delay(TimeSpan.FromSeconds(5 * Temps.time));

                com.disparaitre(Temps.time);//faire disparaitre le commentaire
            }
            else
            {
                com.Height = 40;
                com.Width  = 250;
                com.CoordX = this.coordX;
                com.CoordY = this.coordY - 70;
                if (list.Count != 0)                                                   //si la liste n'est pas vide
                {
                    await recherche_seq(valeur, tabInfo, c, true, comPrincipal, Algo); //Il retourne un entier qui décrit l'echec (0) ou la réussite (1) de la recherche ainsi que la position
                }
                int    typefleche = -1;
                int    typebout   = -1;
                int    Tb;
                Fleche f, f2, f1, f3, f4, f5;
                if (tabInfo[0] == 0)//si la valeur n'a pas été trouvée
                {
                    await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                    com.Text        = "Suppression impossible, la valeur n'existe pas dans la liste !";
                    com.CouleurFond = Brushes.Red;
                    com.Width       = 340;
                    com.apparaitre(Temps.time);//faire apparaitre le commentaire
                    await Task.Delay(TimeSpan.FromSeconds(5 * Temps.time));

                    com.disparaitre(Temps.time);//faire disparaitre le commentaire
                }
                else
                if (tabInfo[0] == 1)// si la valeur a été trouvée
                {
                    comPrincipal.Text           = "Suppression en cours ...";
                    comPrincipal.CouleurBordure = Brushes.Black;
                    comPrincipal.CouleurFond    = Brushes.Yellow;
                    comPrincipal.apparaitre(Temps.time);
                    algo.afficher(Algo);//faire apparaitre l'algorithme déroulant
                    await algo.colorer(couleurAlgo, 0, 0.3 *Temps.time);

                    await algo.colorer(couleurAlgo, 1, 0.3 *Temps.time);

                    await algo.colorer(couleurAlgo, 2, 0.3 *Temps.time);

                    await algo.colorer(couleurAlgo, 3, 0.3 *Temps.time);

                    Point[] tabl = new Point[3];
                    if ((tabInfo[1] == this.list.Count - 1) && (tabInfo[1] > 0)) //Supression d'un élément en fin de liste
                    {
                        await algo.colorer(couleurAlgo, 8, Temps.time);

                        tabl[0] = new Point(this.list[tabInfo[1]].CoordX, this.list[tabInfo[1]].CoordY); //point ou va se deplacer le maillon
                        tabl[1] = new Point(tabl[0].X, tabl[0].Y + 50);                                  //point ou va disparaitre le maillon
                        f1      = this.list[tabInfo[1] - 1].Adr;
                        f2      = this.list[tabInfo[1]].Adr;
                        f1.retirerCanvas(c);
                        com.Text           = "Le précedent du maillon à supprimer pointe son suivant ";
                        com.CouleurFond    = Brushes.LightSkyBlue;
                        com.CouleurBordure = Brushes.Black;
                        com.Width         += 80;
                        com.CoordX         = this.coordX + (tabInfo[1]) * (heightOfmaillon);
                        com.CoordY        += this.coordY + 30;
                        com.apparaitre(Temps.time);  //On adapte le commentaire au contexte
                        await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                        f2.retirerCanvas(c);
                        await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                        typefleche = 5;
                        typebout   = 1;
                        f4         = new Fleche(f1.CoordX, f1.CoordY, f2.Color, ((list.Count - 2) * (heightOfmaillon + tailleFleche + 5) + heightOfmaillon + 5), typefleche, typebout);
                        f4.dessiner(1, c);
                        await algo.colorer(couleurAlgo, 9, Temps.time);

                        this.list[tabInfo[1] - 1].Adr = f4;
                        await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                        this.list[tabInfo[1]].disappear(Temps.time, tabl, 2);
                        await algo.colorer(couleurAlgo, 10, Temps.time);

                        this.list.RemoveAt(this.list.Count - 1);
                        com.disparaitre(Temps.time);//faire disparaitre le commentaire
                    }
                    else
                    {
                        if ((tabInfo[1] < this.list.Count - 1) && (tabInfo[1] > 0)) //Supression d'un élément au milieu de la liste
                        {
                            await algo.colorer(couleurAlgo, 8, Temps.time);

                            tabl[0] = new Point(this.list[tabInfo[1]].CoordX, this.list[tabInfo[1]].CoordY); //On fait disparaître la case à supprimer
                            tabl[1] = new Point(tabl[0].X, tabl[0].Y + 50);
                            f1      = this.list[tabInfo[1] - 1].Adr;
                            Tb      = this.list[tabInfo[1]].Adr.bout.TypeBout;
                            f2      = this.list[tabInfo[1]].Adr;
                            f1.retirerCanvas(c);
                            await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                            com.Text           = "Le précedent du maillon à supprimer pointe son suivant";
                            com.CouleurFond    = Brushes.LightSkyBlue;
                            com.CouleurBordure = Brushes.Black; com.Width += 80;
                            com.CoordX         = this.coordX + tabInfo[1] * (heightOfmaillon);
                            com.CoordY        += this.coordY + 30;
                            com.apparaitre(Temps.time);//faire apparaitre le commentaire
                            f2.retirerCanvas(c);
                            await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

                            typefleche = f2.typefleche + 2;
                            typebout   = f2.bout.TypeBout;
                            f4         = new Fleche(f1.CoordX, f1.CoordY, f1.Color, tailleFleche, typefleche, typebout);
                            f4.dessiner(1, c);
                            await algo.colorer(couleurAlgo, 9, Temps.time);

                            await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

                            this.list[tabInfo[1]].disappear(Temps.time, tabl, 2);
                            await algo.colorer(couleurAlgo, 10, Temps.time);

                            com.disparaitre(Temps.time);//faire disparaitre le commentaire
                            await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                            this.list.RemoveAt(tabInfo[1]);
                            f = new Fleche(f1.CoordX, f1.CoordY, f1.Color, tailleFleche, f1.typefleche, f1.bout.TypeBout);
                            f4.decalAr(f, c);
                            this.list[tabInfo[1] - 1].Adr = f;
                        }
                        else    //Supression d'un élément en debut de liste
                        {
                            await algo.colorer(couleurAlgo, 4, Temps.time);

                            tabl[0] = new Point(this.list[tabInfo[1]].CoordX, this.list[tabInfo[1]].CoordY); //On fait disparaître la case à supprimer
                            tabl[1] = new Point(tabl[0].X, tabl[0].Y + 50);
                            f1      = this.list[list.Count - 1].Adr;
                            f2      = this.list[tabInfo[1]].Adr;
                            f1.retirerCanvas(c);
                            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                            f2.retirerCanvas(c);
                            com.Text           = "Le précedent du maillon à supprimer pointe son suivant";
                            com.CouleurFond    = Brushes.LightSkyBlue;
                            com.CouleurBordure = Brushes.Black;
                            com.Width         += 80;
                            com.CoordX         = this.coordX + tabInfo[1] * (heightOfmaillon);
                            com.CoordY        += this.coordY + 30;
                            com.apparaitre(Temps.time);//faire apparaitre le commentaire
                            await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                            this.list[tabInfo[1]].disappear(Temps.time, tabl, 2);
                            await algo.colorer(couleurAlgo, 5, Temps.time);

                            await Task.Delay(TimeSpan.FromSeconds(2 * Temps.time));

                            this.list.RemoveAt(tabInfo[1]);
                        }
                        Point[] tabPoint = new Point[1];
                        for (int i = tabInfo[1]; i < list.Count; i++)      //Décalages
                        {
                            tabPoint[0] = new Point((i) * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY);
                            tabPoint[0] = new Point(this.coordX + ((i) * (heightOfmaillon + tailleFleche + 5)), this.coordY);
                            list[i].Adr.decaler(this.coordX + ((i) * (heightOfmaillon + tailleFleche + 5)) + heightOfmaillon - 5, this.coordX + ((i) * (heightOfmaillon + tailleFleche + 5)) + heightOfmaillon + tailleFleche - 5); // (i + 1) * (heightOfmaillon + tailleFleche + 5), time);
                            list[i].deplacer(tabPoint, 1);                                                                                                                                                                          //deplacer le maillon
                        }
                        if (list.Count >= 1)                                                                                                                                                                                        //si la liste n'est pas vide
                        {
                            f3 = list[list.Count - 1].Adr;
                            f3.retirerCanvas(c);

                            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                            f5 = new Fleche(this.coordX + ((list.Count - 1) * (heightOfmaillon + tailleFleche + 5)) + heightOfmaillon - 5, f3.CoordY, f3.Color, (list.Count - 1) * (heightOfmaillon + tailleFleche + 5) + heightOfmaillon + 5, 5, 1);
                            f5.dessiner(1, c);
                            await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);

                            await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

                            list[list.Count - 1].Adr = f5;
                        }
                        await algo.colorer(couleurAlgo, 11, 0.3 *Temps.time);

                        if (tabInfo[1] == 0)
                        {
                            com.disparaitre(Temps.time);//faire disparaitre le commentaire
                        }
                        for (int i = tabInfo[1]; i < list.Count - 1; i++)
                        {
                            list[i].Adr.CoordX = (this.coordX + ((i) * (heightOfmaillon + tailleFleche + 5)) + heightOfmaillon - 5);
                        }
                        comPrincipal.disparaitre(Temps.time); //faire disparaitre le commentaire
                    }
                    algo.disparaitre(Algo);                   //faire disparaitre l'algorithme déroulant
                }
            }
        }
Ejemplo n.º 19
0
        public async Task trieeBulle(Canvas c, Commentaire comPrincipal, Canvas Alg)
        {
            int     i, m, i1, j1;
            Algo    algo = new Algo(5, coordX_Algo, coordY_Algo);
            Boolean modif;

            m     = tailleTab;
            modif = true;

            SolidColorBrush couleurPermute        = Brushes.Red;
            SolidColorBrush couleurPermutePas     = Brushes.Green;
            SolidColorBrush couleurCaseAleurPlace = Brushes.LightGreen;

            comPrincipal.Text           = "trie par bulle\n Principe : on parcourt tout le tableau et si \nelem[i] > elem[i + 1], on les permute.\n Il est évident que plusieurs passages sur l'ensemble \ndes éléments sont nécessaires.\nEt on s’arrêtera lorsqu’il n’y a plus de permutations.   ";
            comPrincipal.CouleurFond    = couleurComPrincipal;
            comPrincipal.CouleurBordure = Brushes.Black;
            comPrincipal.Width          = 300;
            comPrincipal.Height         = 110;
            algo.afficher(Alg);
            await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time);

            Commentaire com = new Commentaire("", Brushes.Black, coordX, coordY + 100, 120, 50, couleurPermute, couleurPermute);

            com.ajouterCanvas(c);
            com.opacity = 0;
            comPrincipal.apparaitre(0);
            while ((modif == true) || (m > 2))
            {
                modif = false;
                await algo.colorer(couleurAlgo, 1, Temps.time);

                for (i = 0; i < m - 1; i++)
                {
                    await algo.colorer(couleurAlgo, 2, Temps.time);

                    if (tab[i].Valeur > tab[i + 1].Valeur)
                    {
                        await algo.colorer(couleurAlgo, 3, Temps.time);

                        permuterDeuxCase(i, i + 1, couleurPermute, couleurPermutePas);
                        await algo.colorer(couleurAlgo, 4, 2 *Temps.time);

                        i1                 = i + 1;
                        j1                 = i + 2;
                        com.Text           = tab[i + 1].Valeur + " > " + tab[i].Valeur + " ." + "\nOn permute \n" + "les cases : " + i1 + " et " + j1;
                        com.CouleurFond    = couleurPermute;
                        com.CouleurBordure = couleurPermute;
                        com.Width          = 130;
                        com.Height         = 60;
                        com.apparaitre(Temps.time);
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time * 3));

                        com.disparaitre(Temps.time / 2);
                        tab[i].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                        tab[i + 1].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);

                        modif = true;
                    }
                    else
                    {
                        com.Text = "On permute pas \n on passe au suivant ";

                        com.CouleurFond    = couleurPermutePas;
                        com.CouleurBordure = couleurPermutePas;
                        com.Width          = 120;
                        com.Height         = 50;
                        com.apparaitre(Temps.time);

                        tab[i].colorChamp(couleurPermutePas, this.couleurBordureCase, 1);
                        tab[i + 1].colorChamp(couleurPermutePas, this.couleurBordureCase, 1);


                        await Task.Delay(TimeSpan.FromSeconds(Temps.time * 3));

                        com.disparaitre(Temps.time / 2);

                        tab[i].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                        tab[i + 1].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
                    }
                    await algo.colorer(couleurAlgo, 5, Temps.time);
                }
                await algo.colorer(couleurAlgo, 6, Temps.time);

                tab[m - 1].colorChamp(couleurCaseAleurPlace, Brushes.Green, 1);
                m = m - 1;
            }
            for (i = 0; i < TailleTab; i++)
            {
                tab[i].colorChamp(this.couleurFondCase, this.couleurBordureCase, 1);
            }

            comPrincipal.disparaitre(0);
            await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);

            algo.disparaitre(Alg);
        }
Ejemplo n.º 20
0
        public async static Task produit(Matrice matA, Matrice matB, Matrice produit, Canvas c, double x, double y, Commentaire comPrincipal, Canvas Algo)
        /* Produit matriciel de la matrice A x la matrice B, et rangement du résultat dans la matrice Produit*/
        {
            Algo        algo = new Algo(28, coordX_Algo, coordY_Algo);
            Commentaire com1 = new Commentaire("Nombre de colonnes de la première\nmatrice: " + matA.nbColonnes.ToString(), Brushes.Black, matA.coordX, matA.coordY - 60, 210, 50, couleurCom, Brushes.White);
            Commentaire com2 = new Commentaire("Nombre de lignes de la deuxieme\nmatrice: " + matB.nbLignes.ToString(), Brushes.Black, matB.coordX + matB.nbColonnes * widthOfcase + 20, matB.coordY + 50, 210, 50, couleurCom, Brushes.White);

            comPrincipal.Text        = "Produit matriciel"; //Animation de la comparaison entre le nombre de colonnes de la matrice A et le nombre de lignes de la matrice B
            comPrincipal.CouleurFond = couleurComPrincipal;
            comPrincipal.apparaitre(0);
            com1.ajouterCanvas(c);
            com1.apparaitre(Temps.time);
            com2.ajouterCanvas(c);
            com2.apparaitre(Temps.time);
            await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

            com1.disparaitre(Temps.time);
            com2.disparaitre(Temps.time);
            if (matA.nbColonnes == matB.nbLignes)
            {
                algo.afficher(Algo);                                 //Affichage de l'algorithme
                await algo.colorer(couleurAlgo, 0, 0.5 *Temps.time); //Indication de l'étape en cours dans l'algo

                produit.nbLignes         = matA.nbLignes;
                produit.nbColonnes       = matB.nbColonnes;
                produit.coordX           = x;
                produit.coordY           = y;
                produit.tab              = new Case[matA.nbLignes, matB.nbColonnes]; //Initialisation de la matrice produit
                comPrincipal.Width       = 250;
                comPrincipal.Text        = "Nombre de lignes = Nombre de colonnes\nProduit matriciel en cours...";
                comPrincipal.CouleurFond = couleurComPrincipal;
                await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

                com1.Text   = "Nombre de lignes de la première\nmatrice: " + matA.NbLignes.ToString();      //Récupération du nombre de lignes de la matrice A et du nombre de colonnes de la matrice B
                com1.CoordX = matA.coordX - 220;                                                            //Pour la création de la matrice produit
                com1.CoordY = matA.coordY + 50;
                com1.apparaitre(Temps.time);
                com2.Text   = "Nombre de colonnes de la deuxième\nmatrice: " + matA.NbLignes.ToString();
                com2.CoordX = matB.coordX;
                com2.CoordY = matB.coordY - 60;
                com2.apparaitre(Temps.time);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

                Commentaire com3 = new Commentaire("Matrice produit de type\n" + matA.nbLignes.ToString() + " x " + matB.nbColonnes.ToString(), Brushes.Black, x - 180, y + heightOfcase, 150, 50, couleurCom, Brushes.White);
                com3.ajouterCanvas(c);
                com3.apparaitre(Temps.time);
                Matrice squelette = new Matrice(matA.nbLignes, matB.nbColonnes, x, y);
                for (int i = 0; i < matA.nbLignes; i++)     //Création d'un corps vide pour la matrice produit
                {
                    for (int j = 0; j < matB.nbColonnes; j++)
                    {
                        squelette.tab[i, j] = new Case(0, x + j * widthOfcase, y + i * heightOfcase, 1, heightOfcase, widthOfcase, matA.couleurFondCase, couleurClignottement, 1);
                        squelette.tab[i, j].TextBLock.Opacity = 0;
                    }
                }
                squelette.afficher(c);
                await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));

                TextBlock textBlock = new TextBlock();      //textBlock pour afficher l'oépration en cours (multiplications)
                textBlock.FontFamily = new FontFamily("Poiret One");
                textBlock.Foreground = Brushes.Blue;
                Canvas.SetLeft(textBlock, x /*+ (matB.nbColonnes + 1) * widthOfcase /2*/);
                Canvas.SetTop(textBlock, y - 50);
                c.Children.Add(textBlock);

                Point[] tabPoint = new Point[1];
                for (int i = 0; i < matA.nbLignes; i++)
                {
                    await algo.colorer(couleurAlgo, 1, 0.5 *Temps.time);        //Affichage de l'étape n cours dans l'algo

                    if (i != 0)
                    {
                        com1.Text = (i + 1).ToString() + "ème ligne";           //Explication de l'étape en commentaire
                    }
                    else
                    {
                        com1.Text = (i + 1).ToString() + "ère ligne";
                    }
                    com1.CoordX = matA.coordX - 100;
                    com1.CoordY = matA.coordY + 50 * i + 5;
                    com1.Height = 40;
                    com1.Width  = 80;
                    com1.apparaitre(Temps.time);
                    for (int p = 0; p < matA.nbColonnes; p++)
                    {
                        matA.tab[i, p].BackgroundColor = couleurSelection;                                          //Sélection de la ligne de la matrice A
                    }
                    for (int j = 0; j < matB.nbColonnes; j++)
                    {
                        if (j != 0)
                        {
                            com2.Text = (j + 1).ToString() + "ème colonne";
                        }
                        else
                        {
                            com2.Text = (j + 1).ToString() + "ère colonne";
                        }
                        com2.CoordX = matB.coordX + 50 * j - 20;
                        com2.CoordY = matB.coordY - 50;
                        com2.Height = 40;
                        com2.Width  = 90;
                        com2.apparaitre(Temps.time);
                        for (int p = 0; p < matB.nbLignes; p++)
                        {
                            matB.tab[p, j].BackgroundColor = couleurSelection;      //Sélection de la colonne de la matrice B
                        }
                        await algo.colorer(couleurAlgo, 2, 0.5 *Temps.time);        //Affichag de l'étape en cours dans l'algo

                        await algo.colorer(couleurAlgo, 3, 0.5 *Temps.time);

                        int a = 0;
                        await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                        for (int k = 0; k < matA.nbColonnes; k++)       //Produit matriciel
                        {
                            await algo.colorer(couleurAlgo, 4, 0.5 *Temps.time);

                            await algo.colorer(couleurAlgo, 5, 0.5 *Temps.time);

                            //await Task.Delay(50);
                            matA.tab[i, k].clignoter(couleurClignottement, matA.couleurBordureCase, matA.tab[i, k].BorderThick, 2);     //clignottement des cases à multiplier
                            matB.tab[k, j].clignoter(couleurClignottement, matB.couleurBordureCase, matB.tab[k, j].BorderThick, 2);
                            textBlock.FontSize = 15;
                            if (k != 0)
                            {
                                textBlock.Text += " + " + matA.tab[i, k].Valeur.ToString() + " x " + matB.tab[k, j].Valeur.ToString();
                            }
                            else
                            {
                                textBlock.Text = matA.tab[i, k].Valeur.ToString() + " x " + matB.tab[k, j].Valeur.ToString();         //Affichage de l'opération dans le textBlock
                            }
                            a += matA.tab[i, k].Valeur * matB.tab[k, j].Valeur;
                            await Task.Delay(TimeSpan.FromSeconds(Temps.time));

                            matA.tab[i, k].colorChamp(couleurSelection, matA.couleurBordureCase, 1);
                            matB.tab[k, j].colorChamp(couleurSelection, matB.couleurBordureCase, 1);
                            await algo.colorer(couleurAlgo, 6, 0.5 *Temps.time);
                        }
                        produit.tab[i, j] = new Case(a, x, y - heightOfcase / 2, 1, heightOfcase, widthOfcase, matA.couleurFondCase, couleurClignottement, 1);
                        produit.tab[i, j].Forme.Opacity = 0;
                        produit.tab[i, j].afficher(c);
                        textBlock.Text = "";
                        tabPoint[0]    = new Point(x + j * widthOfcase, y + i * heightOfcase);
                        await produit.tab[i, j].appear(tabPoint, 1);        //calcul du résultat et déplacement dans la matrice produit
                        await Task.Delay(50);

                        produit.tab[i, j].Forme.Opacity = 1;
                        for (int p = 0; p < matB.nbLignes; p++)
                        {
                            matB.tab[p, j].colorChamp(matB.couleurFondCase, matB.couleurBordureCase, 1);
                        }
                        await algo.colorer(couleurAlgo, 7, 0.5 *Temps.time);
                    }
                    for (int p = 0; p < matA.nbColonnes; p++)
                    {
                        matA.tab[i, p].colorChamp(matA.couleurFondCase, matA.couleurBordureCase, 1);
                    }
                    await algo.colorer(couleurAlgo, 8, 0.5 *Temps.time);
                }
                com1.disparaitre(Temps.time);
                com2.disparaitre(Temps.time);
                com3.disparaitre(Temps.time);
                squelette.masquer(c);
                comPrincipal.Text        = "Produit effectué avec succès !";
                comPrincipal.CouleurFond = couleurComPrincipal;
                for (int i = 0; i < produit.nbLignes; i++)
                {
                    for (int j = 0; j < produit.nbColonnes; j++)
                    {
                        produit.tab[i, j].BorderColor = matA.couleurBordureCase;
                    }
                }
                await algo.colorer(couleurAlgo, 9, 0.5 *Temps.time);

                algo.disparaitre(Algo);
            }
            else
            {
                comPrincipal.CouleurFond = Brushes.Red;         //Commentaire d'échec de produit
                comPrincipal.Text        = "Impossible de faire le produit\nLe nombre de colonnes de la première matrice\nest différent du nombre de lignes de la 2ème";
                await Task.Delay(TimeSpan.FromSeconds(Temps.time * 2));
            }
        }