Example #1
0
        public static void TestArray_ListFile(int seed)
        {
            int         n        = 12;
            string      filename = @"myTestArray.dat";
            MyFileArray myarray  = new MyFileArray(filename, n, seed);

            using (myarray.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("---FileArray---");
                myarray.Print(n);
                Console.WriteLine();
                Console.WriteLine("---HeapSortedFileArray---");
                HeapSortArray.HeapSortas(myarray);
                myarray.Print(n);
                Console.WriteLine();
            }
            filename = @"myTestList.dat";
            MyFileList mylist = new MyFileList(filename, n, seed);

            using (mylist.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("---FileList---");
                mylist.Print(n);
                Console.WriteLine();
                Console.WriteLine("---HeapSortedFileList---");
                HeapSortList.HeapSortas(mylist);
                mylist.Print(n);
                Console.WriteLine();
            }
        }
Example #2
0
        public static void AnalysisFILEArray_List(int seed, int kiek)
        {
            string filename = @"myTestArray.dat";
            int    n        = duomskc;

            Console.WriteLine("FileArray HeapSort");
            for (int i = 0; i < kiek; i++)
            {
                MyFileArray myarray = new MyFileArray(filename, n, seed);
                Stopwatch   timer   = new Stopwatch();
                using (myarray.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
                {
                    timer.Start();
                    Program.HeapSortArray.HeapSortas(myarray);
                    timer.Stop();
                }
                //myarray.Print(n);
                Console.WriteLine("{0,-10}{1}", n, timer.Elapsed);
                n = n * 2;
            }
            Console.WriteLine();
            filename = @"myTestList.dat";
            n        = duomskc;
            Console.WriteLine("FileList HeapSort");
            Console.WriteLine("N         RunTime");
            for (int i = 0; i < kiek; i++)
            {
                MyFileList mylist = new MyFileList(filename, n, seed);
                Stopwatch  timer  = new Stopwatch();
                using (mylist.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
                {
                    timer.Start();
                    Program.HeapSortList.HeapSortas(mylist);
                    timer.Stop();
                }
                //mylist.Print(n);
                Console.WriteLine("{0,-10}{1}", n, timer.Elapsed);
                n = n * 2;
            }
            Console.WriteLine();
            Console.WriteLine("---PABAIGA---");
        }
Example #3
0
        public void HeapSortDISK(int NumberOfElements)
        {
            int startInt = 0; int finishInt = 0;

            Console.WriteLine("\nSorting in DISK memory");
            long        time;
            long        time2;
            int         ArrayOP;
            int         ListOP;
            Stopwatch   x = new Stopwatch();
            MyFileArray b = new MyFileArray("array.dat", NumberOfElements * 12);
            MyFileList  a = new MyFileList("test.dat", NumberOfElements * 12);

            Console.WriteLine("Ar norite pamatyti DISKINĖJE atmintyje sugeneruotas aibes? Įvesti: Y/N");
            string YN  = Console.ReadLine();
            bool   yes = false;

            if (YN == "y" || YN == "Y")
            {
                yes = true;
            }

            if (yes)
            {
                Console.WriteLine("Nurodykite intervala, kuriuos elementus norite pamatyti:");
                Console.WriteLine("Nuo: ");
                startInt = int.Parse(Console.ReadLine());
                Console.WriteLine("Iki: ");
                finishInt = int.Parse(Console.ReadLine());
                Console.WriteLine("LIST AIBE:");
                for (int i = startInt - 1; i < finishInt - 1; i++)
                {
                    Console.WriteLine($"{(i + 1)}. " +
                                      a.GetByIndex(i).ToString());
                }
                Console.WriteLine();
                Console.WriteLine("ARRAY AIBE:");
                for (int i = startInt - 1; i < finishInt - 1; i++)
                {
                    Console.WriteLine($"{(i + 1)}. " + b[i].ToString());
                }
            }
            Console.WriteLine("Ar norite pamatyti surikiuotas aibes? Y/N");
            string rikiuotiYN   = Console.ReadLine();
            bool   rikiuotiAibe = false;

            if (rikiuotiYN == "Y" || rikiuotiYN == "y")
            {
                rikiuotiAibe = true;
            }

            x.Reset();
            x.Start();
            b.sort(b, NumberOfElements);
            x.Stop();
            time2   = x.ElapsedMilliseconds;
            ArrayOP = b.getOpCount();
            Console.WriteLine($"Finished ARRAY sorting items, elapsed time: {(double)time2/1000}ms  | Operations made: {ArrayOP}");

            Console.WriteLine("---------------------");

            x.Reset();
            x.Start();
            a.startSort(NumberOfElements);
            x.Stop();
            time   = x.ElapsedMilliseconds;
            ListOP = a.getOpCount();
            Console.WriteLine($"Finished LIST sorting items, elapsed time: {(double)time/1000}ms | Operations made: {ListOP}");
            Console.WriteLine("--------------------");
            if (rikiuotiAibe)
            {
                Console.WriteLine("Nurodykite intervala, kuriuos elementus norite pamatyti:");
                Console.WriteLine("Nuo:");
                int pradzia = int.Parse(Console.ReadLine());
                Console.WriteLine("Iki:");
                int pabaiga = int.Parse(Console.ReadLine());
                Console.WriteLine("Diske surikiuotas masyvas:");
                for (int i = pradzia - 1; i < pabaiga - 1; i++)
                {
                    Console.WriteLine(b[i].ToString());
                }
                Console.WriteLine("Diske surikiuotas LIST:");
                for (int i = pradzia - 1; i < pabaiga - 1; i++)
                {
                    Console.WriteLine(a.GetByIndex(i).ToString());
                }
            }
            b.Close();
            a.Close();
            Console.WriteLine($"Items: {NumberOfElements} ===> List: {(double)time/1000} ms | Operations: {ListOP}  vs  Array: {(double)time2/1000} ms | Operations: {ArrayOP}");
            Console.ReadKey();
        }