Jump to content

C# Question


Mordred

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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