You're trying to assign a single
int
variable (
value
) to an array (
arr
), which obviously won't work.
You're also trying to sort and output the array on each iteration of the first
foreach
loop, which is almost certainly not what you want.
Move the sorting and output outside of the
foreach
loop, and use
values.ToArray()
to get an array of values.
You'll also want to use the array's
Length
property instead of the variable
n
, in case the text doesn't contain exactly
n
valid integers.
foreach (string line in text)
{
int value;
if (int.TryParse(line,out value))
{
values.Add(value);
}
}
int[] arr = values.ToArray();
for (i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
HeapSort(arr, arr.Length);
Console.Write("\nSorted Array is: ");
for (i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}