|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace RecursiveVsIterative
{
class Program
{
public enum Opt
{
Iterative = 0,
Recursive = 1,
RecursiveOpt =2
};
static void Main(string[] args)
{
if (args == null || args.Length == 0)
{
Console.WriteLine("Needed additional prameter: 0-iterative, 1-recursive, 2-recursive optimized");
return;
}
int opt;
if (!int.TryParse(args[0], out opt)
|| opt > 2
|| opt < 0)
{
Console.WriteLine("Invalid Parameter needed : 0-iterative, 1-recursive, 2-recursive optimized");
return;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Press CTRL + C when you done");
Console.ResetColor();
while (true)
{
//clears the "memoization"
RecursiveIterative.resultHistory.Clear();
Console.WriteLine();
Console.Write("I need n ");
string s = Console.ReadLine();
int n;
if (int.TryParse(s, out n))
{
Stopwatch sw = Stopwatch.StartNew();
switch ((Opt)opt)
{
case Opt.Iterative:
RecursiveIterative.FibonacciIterative(n);
break;
case Opt.Recursive:
RecursiveIterative.FibonacciRecursive(n);
break;
case Opt.RecursiveOpt:
RecursiveIterative.FibonacciRecursiveOpt(n);
break;
}
sw.Stop();
Console.WriteLine("{0} result {1}! in {2} ticks", (Opt)opt, n, sw.ElapsedTicks);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
In the last couple of years I'm working as Microsoft sub contractor in various project types - LOB, applications, CnC applications and Distributed applicaitons all of them considered to be extra large in tems of man power (or brain power), duration and geographic destribution between connected sites.