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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.