Hello, I am trying to sort an array of random numbers by passing it to a method Sort(), sort the array, and then pass the entire array back to the calling program. Each time I run this though, the array doesn't seem to sort. I'm not sure if the problem lies with my sorting algorithm or if it has something to do with calling the function.
Code:
static void HighAverage(int[] a) {
for (int i = 0; i < a.Length; i++)
{
if ((i + 1) % 10 == 0 && i != 0)
Console.WriteLine(a[i]);
else
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
Sort(ref a);
for (int i = 0; i < a.Length; i++)
{
if ((i + 1) % 10 == 0 && i != 0)
Console.WriteLine(a[i]);
else
Console.Write("{0} ", a[i]);
}
}
static void Sort(ref int[] a)
{
int min, t;
for (int i = 0; i < a.Length - 1; i++)
{
min = i;
for (int j = (i + 1); j < a.Length; j++)
{
if (a[j] < a[min])
min = j;
}
t = a[min]; a[min] = a[i]; a[i] = a[min];
}
}