Witam,
czy istnieje możliwość generowania, np. za pomocą jakiejś metody, liczb pseudolosowych innego typu niż int?
Aby przybliżyć trochę problem wrzucam treść zadania.
A tu kod dla jednego z algorytmów, o których mowa w treści zadania:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Double
{
class Program
{
static int N = 10;//200000; //Liczebność zbioru
static double[] Array;
//Program główny
static void Main(string[] args)
{
Stopwatch zegar = new Stopwatch();
//Console.WriteLine("***** SORTOWANIE PRZEZ WSTAWIANIE *****\n\n" + " n | f=t(n)\n--------------------");
//for (int i = 10; i <= N; i *= 2)
//{
// FillArray(i);
// zegar.Start();
// InsertionSort(i);
// zegar.Stop();
// Console.WriteLine(i + " | " + Math.Round(zegar.ElapsedTicks * (1.0 / Stopwatch.Frequency), 5));
//}
//SPRAWDZENIE CZY SORTOWANIE DZIALA PRAWIDLOWO
Console.WriteLine("Przed sortowaniem:");
FillArray(N);
zegar.Start();
InsertionSort(N);
zegar.Stop();
Console.WriteLine("\n\nPo sortowaniu:");
for (int i = 0; i < N; i++)
{
Console.Write("{0}, ", Array[i]);
}
Console.WriteLine("\n\nCzas sortowania: {0}", Math.Round(zegar.ElapsedTicks * (1.0 / Stopwatch.Frequency), 5));
Console.ReadLine();
}
static void FillArray(int size)
{
Random rnd = new Random(Guid.NewGuid().GetHashCode());
Array = new double[size];
for (int i = 0; i < size; i++)
{
Array[i] = rnd.Next(101); // <-- Wypełnienie tablicy wartościami.
// W tym przypadku miałyby to być wartości typu DOUBLE.
Console.Write("{0}, ", Array[i]);
}
}
//Program sortujący
static void InsertionSort(int n)
{
int k;
double x;
for (int i = n - 2; i >= 0; i--)
{
x = Array[i];
k = i + 1;
while ((k < n) && (x > Array[k]))
{
Array[k - 1] = Array[k];
k++;
}
Array[k - 1] = x;
}
}
}
}
Z góry dzięki za pomoc.