예제 #1
0
        public void chargement_alea(int nbvaleur, Canvas c) //initialisation de la liste avec "nbvaleur" maillons
        {
            Random  rndNumber = new Random();               // gérération aléatoire des valeurs
            Boolean stop      = new Boolean();

            int[] tabValeur = new int[nbvaleur];
            list = new List <Maillon_bi>();
            Maillon_bi  maillon;
            Commentaire comChar_Impo = new Commentaire("Chargement impossible le nombre de valeur dépasse le nombre maximum", Brushes.Black, this.coordX + 50, this.coordY - 50, 400, 30, Brushes.PaleGreen, Brushes.White);
            int         i;

            if (nbvaleur > nbmaillonmax)//Si le nombre de maillons et supérieur au nombre max
            {
                comChar_Impo.ajouterCanvas(c);
                comChar_Impo.disparaitre(5);
            }
            else
            {
                for (i = 0; i < nbvaleur; i++) //Géneration des nombres aléatoires
                {
                    stop = true;
                    while (stop == true)
                    {
                        tabValeur[i] = rndNumber.Next(0, 40);
                        stop         = false;
                        for (int j = i - 1; j >= 0; j--)
                        {
                            if (tabValeur[i] == tabValeur[j])
                            {
                                stop = true;
                            }
                        }
                    }
                }
                if (this.triee)
                {
                    Array.Sort(tabValeur);             // tabValuer doit être triée si l'attribut triee est à vrai
                }
                if (nbvaleur == 1)
                {
                    maillon = new Maillon_bi(tabValeur[0], this.coordX + tailleFleche, this.coordY, 50, 100, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 3, 3, tailleFleche);
                    list.Add(maillon);//ajouter le maillon dans la liste
                }
                else
                {
                    maillon = new Maillon_bi(tabValeur[0], this.coordX + tailleFleche, this.coordY, 50, 100, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 3, 1, tailleFleche);
                    list.Add(maillon);
                    for (i = 1; i < nbvaleur - 1; i++)//Création des maillons
                    {
                        maillon = new Maillon_bi(tabValeur[i], this.coordX + i * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY, widthOfmaillon, heightOfmaillon, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 2, 1, tailleFleche);
                        list.Add(maillon);
                    }
                    //Partie du dernier maillon qui est à Null
                    maillon = new Maillon_bi(tabValeur[nbvaleur - 1], this.coordX + i * (heightOfmaillon + tailleFleche) + tailleFleche, this.coordY, 50, 100, couleurFondMaillon, couleurBordureMaillon, 2, 2, 1, 2, 3, tailleFleche);
                    list.Add(maillon);
                }
            }
        }
예제 #2
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
        }