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 TestArray_List(int seed)
        {
            int         n       = 12;
            MyDataArray myArray = new MyDataArray(n, seed);

            Console.WriteLine("---Array---");
            myArray.Print(n);
            Console.WriteLine();
            Console.WriteLine("---HeapSortedArray---");
            HeapSortArray.HeapSortas(myArray);
            myArray.Print(n);
            Console.WriteLine();
            MyDataList myList = new MyDataList(n, seed);

            Console.WriteLine("---List---");
            myList.Print(n);
            Console.WriteLine();
            Console.WriteLine("---HeapSortedList---");
            HeapSortList.HeapSortas(myList);
            myList.Print(n);
            Console.WriteLine();
        }
Example #3
0
        public void HeapSortRAM(int NumberOfElements)
        {
            int startInt, finishInt;
            int startas = 0; int finisas = 0;
            LinkedList <IntFloat> IntList         = new LinkedList <IntFloat>();
            Random    random                      = new Random();
            Stopwatch measure                     = new Stopwatch();
            HeapSortLinkedList <IntFloat> IntSort = new HeapSortLinkedList <IntFloat>();
            long IntTime;
            int  ArrayOP;
            int  ListOP;

            for (int y = 0; y < NumberOfElements; y++)
            {
                IntFloat x = new IntFloat(random.Next(0, 1000), (float)random.NextDouble());
                IntList.addItem(x);
            }
            IntFloat[] IntFloatArray = GenerateArray(NumberOfElements);

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

            if (YN == "Y" || YN == "y")
            {
                yesNo = true;
            }
            if (yesNo)
            {
                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)}. " +
                                      IntList.returnNodeByIndex(i).ToString());
                }
                Console.WriteLine();
                Console.WriteLine("ARRAY AIBE:");
                for (int i = startInt - 1; i < finishInt - 1; i++)
                {
                    Console.WriteLine($"{(i+1)}. " + IntFloatArray[i].ToString());
                }
            }
            Console.WriteLine("Ar norite pamatyti surikiuotas aibes? Y/N");
            string rikiuotAib = Console.ReadLine();
            bool   rikiuotYN  = false;

            if (rikiuotAib == "y" || rikiuotAib == "Y")
            {
                rikiuotYN = true;
            }
            Console.WriteLine("\nSorting in OPERATING MEMORY...");
            IntSort.init(IntList);
            measure.Reset();
            measure.Start();
            IntSort.startSort();
            measure.Stop();
            IntTime = measure.ElapsedMilliseconds;
            ListOP  = IntSort.getOpCount();
            Console.WriteLine();
            if (rikiuotYN)
            {
                Console.WriteLine($"Nurodykite intervala nuo {1} iki {NumberOfElements}: ");
                Console.WriteLine("Nuo: ");
                startas = int.Parse(Console.ReadLine());
                Console.WriteLine("Iki: ");
                finisas = int.Parse(Console.ReadLine());
                Console.WriteLine("LIST surikiuota aibe:");
                for (int i = startas - 1; i < finisas - 1; i++)
                {
                    Console.WriteLine(IntList.returnNodeByIndex(i).ToString());
                }
            }
            Console.WriteLine($"List sort: {(double)IntTime/1000} ms | Operations made: {ListOP}");
            IntList.clear();

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

            long IntArrayTime;
            HeapSortArray <IntFloat> IntArraySort = new HeapSortArray <IntFloat>();
            Stopwatch timer = new Stopwatch();

            timer.Reset();
            timer.Start();
            IntArraySort.sort(IntFloatArray);
            timer.Stop();
            IntArrayTime = timer.ElapsedMilliseconds;
            ArrayOP      = IntArraySort.getOpCount();
            if (rikiuotYN)
            {
                Console.WriteLine("Array surikiuota aibe:");
                for (int i = startas - 1; i < finisas - 1; i++)
                {
                    Console.WriteLine(IntFloatArray[i].ToString());
                }
            }
            Console.WriteLine($"Array sort time: {(double)IntArrayTime/1000} ms | Operations made: {ArrayOP.ToString()}");
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine($"Items: {NumberOfElements} ===> List: {(double)IntTime/1000} ms | Operations made: {ListOP}  vs  Array: {(double)IntArrayTime/1000} ms | Operations made: {ArrayOP}");
            Console.WriteLine("-----------------------------------------");
        }