Hello!
I have one error in my program , I dont know why this error appears in 63 Line.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HeapSort
{
class Program
{
void restore(int[] T,int k)
{
int n = T.Length;
int i,j;
i=T[k-1];
while(k<=n/2)
{
j=2*k;
if( (j<n) && (T[j-i] < T[j]) ) j++;
if(i>=T[j-1]) break;
else
{
T[k-1] = T[j-1];
k=j;
}
T[k-1]=i;
}
}
//Sort tab T .
void heapsort(int[] T)
{
int k,swap;
int n = T.Length;
for(k=n/2;k>0;k--) restore(T,k);
do
{
swap=T[0];
T[0]=T[n-1];
T[n-1]=swap;
n--;
restore(T,1);
} while(n>1);
}
static void Main(string[] args)
{
int i;
int[] T = { 12, 3, -12, 9, 34, 23, 1, 81, 45, 17, 9, 23, 11, 4 };
for(i = 0;i <T.Length;i++)
Console.Write(" {0}",T[i]);
Console.WriteLine();
heapsort(T); //THE ERROR
for (i = 0; i < T.Length; i++)
Console.Write(" {0} ", T[i]);
}
}
}