コード例 #1
0
ファイル: Program.cs プロジェクト: DMistera/Algorithms
        private void Task3()
        {
            SortingAlgorithm[] algs = { new QuickSort(), new QuickSort2(), new InsertionSort() };
            Console.WriteLine("Insert the first number of elements (pref 400-800)");
            int   nm    = InputParameter();
            Table table = new Table(3, 21);

            table.StartWithNewThread();
            for (int k = 0; k < 2; k++)
            {
                string distr = k == 0 ? "(Random)" : "(Ascending)";
                Graph  g     = new Graph("Number of elements", "Time[s]");
                foreach (SortingAlgorithm s in algs)
                {
                    Table.Tab tab = new Table.Tab(s.GetName() + " " + distr);
                    table.AddTab(tab);
                    tab.AddLine(new string[] { "Number of elements", "Time (in seconds)", "Number of iterations" });
                    Graph.Data pointData = new Graph.Data(s.GetName() + " " + distr);
                    for (int i = 0; i < 20; i++)
                    {
                        int       n        = nm * (i + 1);
                        Element[] elements = GenerateElements(n, n, k == 0 ? Distribution.Random : Distribution.Ascending);
                        s.Sort(elements);
                        pointData.AddPoint(n, ((float)s.GetElapsedTime() / 1000));
                        string[] line = { n.ToString(), ((float)s.GetElapsedTime() / 1000).ToString("0.00"), s.GetIterationCount().ToString() };
                        tab.AddLine(line);
                    }
                    g.AddData(pointData);
                }
                g.StartWithNewThread();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: DMistera/Algorithms
        private void Task4()
        {
            SortingAlgorithm[] algs = { new CountingSort(), new QuickSort() };
            Console.WriteLine("Insert the first number of elements (pref 5000-15000)");
            int   nm    = InputParameter();
            Table table = new Table(3, 21);

            table.StartWithNewThread();
            Graph[] g = new Graph[2];
            for (int k = 0; k < 2; k++)
            {
                string type = k == 0 ? "[1, 100*n]" : "[1, 0.01*n]";
                g[k] = new Graph("Number of elements", "Time[s]");
                foreach (SortingAlgorithm s in algs)
                {
                    Table.Tab tab = new Table.Tab(s.GetName() + " " + type);
                    table.AddTab(tab);
                    tab.AddLine(new string[] { "Number of elements", "Time (in seconds)", "Number of iterations" });
                    Graph.Data pointData = new Graph.Data(s.GetName() + " " + type);
                    for (int i = 0; i < 20; i++)
                    {
                        int       n        = nm * (i + 1);
                        Element[] elements = GenerateElements(n, k == 0 ? n * 100 : (int)(n * 0.01));
                        s.Sort(elements);
                        pointData.AddPoint(n, ((float)s.GetElapsedTime() / 1000));
                        string[] line = { n.ToString(), ((float)s.GetElapsedTime() / 1000).ToString("0.00"), s.GetIterationCount().ToString() };
                        tab.AddLine(line);
                    }
                    g[k].AddData(pointData);
                }
            }
            g[0].StartWithNewThread();
            g[1].StartWithNewThread();
        }
コード例 #3
0
        private void Task2()
        {
            Console.WriteLine("Insert the first number of elements");
            int   nm    = InputParameter();
            Graph g     = new Graph("Number of elements", "Time[s]");
            var   types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes().Where(x => x.BaseType == typeof(SortingAlgorithm));
            Table table = new Table(3, 21);

            table.StartWithNewThread();
            foreach (var x in types)
            {
                SortingAlgorithm s   = (SortingAlgorithm)Activator.CreateInstance(x);
                Table.Tab        tab = new Table.Tab(s.GetName());
                table.AddTab(tab);
                tab.AddLine(new string[] { "Number of elements", "Time (in seconds)", "Number of iterations" });
                Graph.Data pointData = new Graph.Data(s.GetName());
                for (int i = 0; i < 20; i++)
                {
                    int       n        = nm * (i + 1);
                    Element[] elements = GenerateElements(n, n);
                    s.Sort(elements);
                    pointData.AddPoint(n, ((float)s.GetElapsedTime() / 1000));
                    string[] line = { n.ToString(), ((float)s.GetElapsedTime() / 1000).ToString("0.00"), s.GetIterationCount().ToString() };
                    tab.AddLine(line);
                }
                g.AddData(pointData);
            }
            g.StartWithNewThread();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: DMistera/Algorithms
 private void T2(SortingAlgorithm[] ss, Table table, int nm, Graph g)
 {
     foreach (SortingAlgorithm s in ss)
     {
         Table.Tab tab = new Table.Tab(s.GetName());
         table.AddTab(tab);
         tab.AddLine(new string[] { "Number of elements", "Time (in seconds)", "Number of iterations" });
         Graph.Data pointData = new Graph.Data(s.GetName());
         for (int i = 0; i < 20; i++)
         {
             int       n        = nm * (i + 1);
             Element[] elements = GenerateElements(n, n);
             s.Sort(elements);
             pointData.AddPoint(n, ((float)s.GetElapsedTime() / 1000));
             string[] line = { n.ToString(), ((float)s.GetElapsedTime() / 1000).ToString("0.00"), s.GetIterationCount().ToString() };
             tab.AddLine(line);
         }
         g.AddData(pointData);
     }
 }