Esempio n. 1
0
        public JsonResult ordenar(int[] array)
        {
            var vetor = new List <int>(array);
            SortAnimationData dados = Sort.insertionSort(vetor);

            return(Json(new { data = dados }));
        }
Esempio n. 2
0
        public static SortAnimationData insertionSort(List <int> vet)
        {
            var          animationData = new SortAnimationData();
            State        estado        = null;
            BlocoEstados bloco         = null;

            int i, x, temp;
            int r   = 0;
            var tam = vet.Count;

            for (i = 1; i < tam; i++)
            {
                bloco = new BlocoEstados();
                animationData.addBloco(bloco);

                x    = i;
                temp = vet[i];

                while (x - 1 >= 0)
                {
                    if (vet[x - 1] > temp)
                    {
                        vet[x]     = vet[x - 1];
                        vet[x - 1] = temp;



                        estado = new State(x, x - 1, x);
                        bloco.addEstado(estado);


                        x--;
                    }
                    else
                    {
                        break;
                    }
                }
            }



            animationData.setEstadoFinal(vet);
            return(animationData);
        }