Witam, mam problem by sprawdzić szybkość działania. Wywala mi 3 błędy, lecz nie mam pojęcia jak je naprawić.
Poniżej kod.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication23
{
class Program
{
void InsertionSort(int[] t)
{
for (int i = 1; i < t.Length; i++)
{
int j = i;
int Buf = t[j];
while ((j > 0) && (t[j - 1] > Buf))
{
t[j] = t[j - 1];
j--;
}
t[j] = Buf;
}
}
static void Main(string[] args)
{
int[] t = new int[150000];
for (int a = 150000; a > 0; a--)
{
t[a] = a;
}
const int NIter = 15;
Console.WriteLine("n\tt[s]");
for (int u = 50000; u < 150001; u+=1000)
{
double ElapsedSeconds;
long ElapsedTime = 0, MinTime = long.MaxValue, MaxTime = long.MinValue, IterationElapsedTime; for (int n = 0; n < (NIter + 1 + 1); ++n)
{
long StartingTime = Stopwatch.GetTimestamp();
InsertionSort(int[] t);
long EndingTime = Stopwatch.GetTimestamp();
IterationElapsedTime = EndingTime - StartingTime;
ElapsedTime += IterationElapsedTime;
}
ElapsedTime -= (MinTime + MaxTime);
ElapsedSeconds = ElapsedTime * (1.0 / (NIter * Stopwatch.Frequency)); Console.WriteLine("{0}\t{1}", u, ElapsedSeconds.ToString("F4"));
}
}
}
}
Błąd wywala w tej linijce.
InsertionSort(int[] t);