Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Without changing the method under \"public static void Sort(ref int[] x)\" or an

ID: 3698927 • Letter: W

Question

Without changing the method under "public static void Sort(ref int[] x)" or any of the code, where is the bug that is not sorting the array after compling and explain why you changed or added to the code to sort the array.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bi_direactional4_HW
{
class Program
{
static void Main(string[] args)
{
int[] x = { 26, 86, 2, 65, 83, 1 };
Sort(ref x);

for (int i = 0; i <= x.Length - 1; i++)
{
Console.Write(x[i] + " ");
}
Console.ReadLine();
}

public static void Sort(ref int[] x)
{
int i, j, temp;
int increment = 3;

while (increment < 0)
{
for ( i = 0; i < x.Length; i++)
{
j = 1;
temp = x[i];

while ((j >= increment) && (x[j - increment] > temp))
{
x[j] = x[j - increment];
j = j - increment;
}
x[j] = temp;
}
if (increment / 2 != 0)
{
increment = increment / 2;
}
else if (increment == 1)
{
increment = 0;
}
else
{
increment = 1;
}
}
}
}
}

Explanation / Answer

explanation:

In given code:

using System.Collections.Generic;

this code tells that if using Generic in C# it supports all the data type so why you use temp function again

public static void Sort(ref int[] x)
{
int i, j, temp;

Don't do this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote