public void ShellSort()
        {
            for (int gap = intButtons.Length / 2; gap > 0; gap /= 2)
            {
                for (int i = gap; i < intButtons.Length; i += 1)
                {
                    int temp = this[i].Value;
                    intButtons[i].Location        = new Point(intButtons[i].Location.X, ThongSo.Panel.Height - ThongSo.PaddingBotPanel + 2);
                    intButtons[i].BackColor       = Color.Aqua;
                    intButtons[i - gap].BackColor = Color.Yellow;
                    Thread.Sleep(ThongSo.Sleep);
                    intButtons[i - gap].BackColor = ThongSo.clIntButton;
                    int j;
                    for (j = i; j >= gap && this[j - gap] > temp; j -= gap)
                    {
                        intButtons[j - gap].BackColor = Color.Red;
                        intButtons[j].BackColor       = Color.Red;
                        Thread.Sleep(ThongSo.Sleep);
                        int x = intButtons[j].Location.X;
                        intButtons[j].Location = new Point(intButtons[j - gap].Location.X, ThongSo.Panel.Height - ThongSo.PaddingBotPanel + 2);

                        Thread.Sleep(ThongSo.Sleep);
                        IntButton.Set(ref intButtons[j], intButtons[j - gap].Value);
                        ThongSo.onArrayaccesses();
                        ThongSo.onArrayaccesses();
                        intButtons[j].Location = new Point(x, intButtons[j].Location.Y);


                        intButtons[j - gap].Location  = new Point(intButtons[j - gap].Location.X, ThongSo.Panel.Height - ThongSo.PaddingBotPanel + 2);
                        intButtons[j - gap].BackColor = Color.Aqua;
                        intButtons[j - gap].Text      = temp.ToString();
                        intButtons[j - gap].Size      = new Size(ThongSo.WigthIntButton, temp);
                        Thread.Sleep(ThongSo.Sleep);
                        intButtons[j].BackColor = ThongSo.clIntButton;
                    }
                    Thread.Sleep(ThongSo.Sleep);
                    IntButton.Set(ref intButtons[j], temp);
                    ThongSo.onArrayaccesses();
                    intButtons[j].BackColor = ThongSo.clIntButton;
                    Thread.Sleep(ThongSo.Sleep);
                }
            }
            ThongSo.IsAlive = false;
            //isALive = false;
        }
        public void InsertionSort()
        {
            int j;
            int t;

            intButtons[0].BackColor = Color.Yellow;
            for (int i = 1; i < intButtons.Length; i++)
            {
                j = i - 1;
                t = this[i].Value;
                ThongSo.onArrayaccesses();
                intButtons[i].Location  = new Point(intButtons[i].Location.X, ThongSo.Panel.Height - ThongSo.PaddingBotPanel + 2);
                intButtons[i].BackColor = Color.Aqua;
                Thread.Sleep(ThongSo.Sleep);
                while (j >= 0 && t < intButtons[j])
                {
                    Thread.Sleep(ThongSo.Sleep);
                    IntButton.Set(ref intButtons[j + 1], intButtons[j].Value);
                    ThongSo.onArrayaccesses();
                    ThongSo.onArrayaccesses();
                    intButtons[j + 1].BackColor = Color.Yellow;
                    intButtons[j].Location      = new Point(intButtons[j].Location.X, ThongSo.Panel.Height - ThongSo.PaddingBotPanel + 2);
                    intButtons[j].BackColor     = Color.Aqua;
                    intButtons[j].Text          = t.ToString();
                    intButtons[j].Size          = new Size(ThongSo.WigthIntButton, t);

                    j--;
                }

                IntButton.Set(ref intButtons[j + 1], t);
                ThongSo.onArrayaccesses();
                intButtons[j + 1].BackColor = Color.Yellow;
                Thread.Sleep(ThongSo.Sleep);
            }
            ThongSo.IsAlive = false;
        }
        void merge(int l, int m, int r)
        {
            int i, j, k;
            int n1 = m - l + 1;
            int n2 = r - m;

            /* create temp arrays */
            int[] L = new int[n1], R = new int[n2];

            /* Copy data to temp arrays L[] and R[] */
            for (i = 0; i < n1; i++)
            {
                L[i] = this[l + i].Value;

                intButtons[l + i].BackColor = Color.Red;
                //  intButtons[l + i].Location = new Point(intButtons[l + i].Location.X, intButtons[l + i].Location.Y );
            }

            for (j = 0; j < n2; j++)
            {
                R[j] = this[m + 1 + j].Value;
                intButtons[m + 1 + j].BackColor = Color.Blue;
                // intButtons[m + 1 + j].Location = new Point(intButtons[m + 1 + j].Location.X, intButtons[m + 1 + j].Location.Y );
            }

            /* Merge the temp arrays back into arr[l..r]*/
            i = 0; // Initial index of first subarray
            j = 0; // Initial index of second subarray
            k = l; // Initial index of merged subarray
            Thread.Sleep(ThongSo.Sleep);
            while (i < n1 && j < n2)
            {
                //  Thread.Sleep(ThongSo.Sleep);
                ThongSo.onComparisions();
                if (L[i] <= R[j])
                {
                    IntButton.Set(ref intButtons[k], L[i]);
                    ThongSo.onArrayaccesses();
                    intButtons[k].BackColor = Color.Red;
                    // intButtons[k].BackColor = ThongSo.clIntButton;
                    intButtons[k].Location = new Point(intButtons[k].Location.X, intButtons[k].Location.Y + 50);
                    // arr[k] = L[i];
                    i++;
                }
                else
                {
                    //arr[k] = R[j];

                    IntButton.Set(ref intButtons[k], R[j]);
                    ThongSo.onArrayaccesses();
                    intButtons[k].BackColor = Color.Blue;
                    intButtons[k].Location  = new Point(intButtons[k].Location.X, intButtons[k].Location.Y + 50);
                    //   intButtons[k].BackColor = ThongSo.clIntButton;
                    j++;
                }
                k++;
            }

            /* Copy the remaining elements of L[], if there
             * are any */
            while (i < n1)
            {
                //   Thread.Sleep(ThongSo.Sleep);
                // arr[k] = L[i];
                ThongSo.onComparisions();
                IntButton.Set(ref intButtons[k], L[i]);
                ThongSo.onArrayaccesses();
                intButtons[k].BackColor = Color.Red;
                intButtons[k].Location  = new Point(intButtons[k].Location.X, intButtons[k].Location.Y + 50);
                //    intButtons[k].BackColor = ThongSo.clIntButton;
                i++;
                k++;
            }

            /* Copy the remaining elements of R[], if there
             * are any */
            while (j < n2)
            {
                //  Thread.Sleep(ThongSo.Sleep);
                //  arr[k] = R[j];
                ThongSo.onComparisions();
                IntButton.Set(ref intButtons[k], R[j]);
                ThongSo.onArrayaccesses();
                intButtons[k].BackColor = Color.Blue;
                intButtons[k].Location  = new Point(intButtons[k].Location.X, intButtons[k].Location.Y + 50);
                // intButtons[k].BackColor = ThongSo.clIntButton;

                j++;
                k++;
            }
            for (int x = l; x <= r; x++)
            {
                Thread.Sleep(ThongSo.Sleep);
                intButtons[x].BackColor = ThongSo.clIntButton;
                intButtons[x].Location  = new Point(intButtons[x].Location.X, intButtons[x].Location.Y - 50);
            }
        }