0

プログラムにエラーが1つありますが、このエラーが63行に表示される理由がわかりません。

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]);
        }


        }
    }
4

1 に答える 1

2

どのエラーを指定するかを指定すると、それが役立ちます(場合によっては)。ここで私が見ていることの1つは、静的メソッドMainから非静的コード(ヒープソート)を呼び出していることです。本当に必要な場合は、Programのオブジェクトを作成する必要があります。2つのメソッドを静的にします。それは初心者向けです。

于 2010-10-16T12:22:25.377 に答える