Jump to content

C# Question


Recommended Posts

Posted (edited)
6 minutes ago, upotudrop said:

7HV9osE.png

How would one go about this? Yes im stupid as fuck


private void SortArrayWithShellSort()
        {
            int[] array = { 297,183, 464 };
            ShellSort(array);            
        }
       
 
        private void ShellSort(int[] array)
        {
            int n = array.Length;
            int gap = n / 2;
            int temp;
 
            while (gap > 0)
            {
                for (int i = 0; i + gap < n; i++)
                {
                    int j = i + gap;
                    temp = array[j];
 
                    while (j - gap >= 0 && temp < array[j - gap])
                    {
                        array[j] = array[j - gap];
                        j = j - gap;
                    }
 
                    array[j] = temp;
                }
 
                gap = gap / 2;
            }
        }

From google.

Now simply add a console.writeline of the array after each insertion.

 

EDIT:

        static void show_array_elements(int[] arr)
        {
            foreach (var element in arr)
            {
                Console.Write(element + " ");
            }
            Console.Write("\n");

        }

For printing the array

Edited by HunterRS
Posted

Eh more info? What part do you not understand? Do you even have an IDE? I assume this is for school, and if so I'd recommend you to try yourself first, information how to solve all parts of your assignment can be googled. Just copy-pasting something someone gives you will just give you more trouble your next assignment.

Posted (edited)
7 minutes ago, Product said:

Eh more info? What part do you not understand? Do you even have an IDE? I assume this is for school, and if so I'd recommend you to try yourself first, information how to solve all parts of your assignment can be googled. Just copy-pasting something someone gives you will just give you more trouble your next assignment.

You have to start somewhere, no one should just copy paste but going over the code and understanding what each part of it does will help you understand and handle this type of assignments in the future.

Edited by HunterRS

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...