V
V
Vitaliy Todosiychuk2017-09-26 09:14:05
C++ / C#
Vitaliy Todosiychuk, 2017-09-26 09:14:05

Sort 2D array using Shell method in C#?

I need to sort a two-dimensional array using the Shell
method

private void shellSort(int[,] arr)
        {
            int j;
            int step = arr.Length / 2;
            for (int k = 0; k < 1; k++)
            {
                while (step > 0)
                {
                    for (int i = 0; i < (arr.Length - step); i++)
                    {
                        j = i;
                        while ((j >= 0) && (arr[k, j] > arr[k, j + step]))
                            {
                                int tmp = arr[k, j];
                                arr[k, j] = arr[k, j + step];
                                arr[k, j + step] = tmp;
                                j -= step; 
                            }
                    }
                    step = step / 2;
                }
                richTextBox1.Text += "\n" + "mas" + (k + 1) + ": ";
                for (int y = 0; y < Convert.ToInt32(bunifuMaterialTextbox1.Text); y++)
                {
                    richTextBox1.Text += arr[k, y] + " ";
                }
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Todosiychuk, 2017-09-26
@vitaligu

solved, here is the answer

private void shellSort(int[,] arr)
        {
            for (int k = 0; k < 2; k++)
            {
                int j;
                int step = arr.Length / 2;
                while (step > 0)
                {
                    for (int i = 0; i < (Convert.ToInt32(bunifuMaterialTextbox1.Text) - step); i++)
                    {
                        j = i;
                        while ((j >= 0) && (arr[k, j] > arr[k, j + step]))
                            {
                                int tmp = arr[k, j];
                                arr[k, j] = arr[k, j + step];
                                arr[k, j + step] = tmp;
                                j -= step; 
                            }
                    }
                    step = step / 2;
                }
                richTextBox1.Text += "\n" + "mas" + (k + 1) + ": ";
                for (int y = 0; y < Convert.ToInt32(bunifuMaterialTextbox1.Text); y++)
                {
                    richTextBox1.Text += arr[k, y] + " ";
                }
                
            }
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question