Example #1
0
        public void chargementAleatoire(int nbValeur)
        {
            //Crée une liste circulaire de nbValeur valeurs
            Random  rndNumber = new Random();
            Boolean stop      = new Boolean();

            int[] tabValeur = new int[nbValeur];
            list = new List <Maillon>();
            Maillon maillon;
            int     i;

            for (i = 0; i < nbValeur; i++)//Génération de nombres aléatoire
            {
                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
            }
            for (i = 0; i < nbValeur - 1; i++) //On crée les maillons de la liste
            {
                maillon = new Maillon(tabValeur[i], this.coordX + i * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY, 50, 100, couleurFondMaillon, couleurBordureMaillon, 2, 1, 1, tailleFleche);
                list.Add(maillon);//ajouter le maillon dans la liste
            }
            maillon = new Maillon(tabValeur[nbValeur - 1], this.coordX + i * (heightOfmaillon + tailleFleche + 5) + 10, this.coordY, 50, 100, couleurFondMaillon, couleurBordureMaillon, 2, 5, 1, i * (heightOfmaillon + tailleFleche + 5) + heightOfmaillon + 5);
            list.Add(maillon);//ajouter le maillon dans la liste
        }
Example #2
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
        }