Example #1
0
        public static void Test_File_Array_List(int seed, int n)
        {
            Console.WriteLine("\n Išorinėje atmintyje suliejimo rykiavimas\n");
            string    filename;
            Stopwatch watch = new Stopwatch();

            filename = @"mydataarray.dat";
            MyFileArray sortedFileArray;
            MyFileArray myfilearray = new MyFileArray(filename, n, seed);

            Console.WriteLine("\n Masyvas \n");
            myfilearray.Print(n);
            watch.Start();
            sortedFileArray = (MyFileArray)MergeSort(myfilearray);
            watch.Stop();
            var arrayTime = watch.Elapsed;

            Console.WriteLine("\n Surykiuotas masyvas \n");
            sortedFileArray.Print(n);

            filename = @"mydatalist.dat";
            MyFileList sortedFileList;
            MyFileList myfilelist = new MyFileList(filename, n, seed);

            Console.WriteLine("\n Sąrašas \n");
            myfilelist.Print(n);
            watch.Start();
            sortedFileList = (MyFileList)MergeSort(myfilelist);
            watch.Stop();
            var listTime = watch.Elapsed;

            Console.WriteLine("\n išrykiuotas \n");
            sortedFileList.Print(n);
            Console.WriteLine("masyvo vykdymo laikas: " + arrayTime + " sąrašo vykdymo laikas: " + listTime);
        }
Example #2
0
        //--------------------------------------------------------
        //-----------------------------------------------------
        //susietojo sąrašo rikiavimas

        private static DataList MergeSort(DataList unsorted)
        {
            if (unsorted.Length <= 1)
            {
                return(unsorted);
            }

            DataList left;
            DataList right;

            if (unsorted.GetType() == typeof(MyDataList))
            {
                left  = new MyDataList();
                right = new MyDataList();
            }
            else
            {
                left  = new MyFileList();
                right = new MyFileList();
            }
            MyDataStruct data;

            int middle = unsorted.Length / 2;

            data = unsorted.First();
            for (int i = 0; i < middle; i++)  //dalinam sarasa
            {
                left.Add(data);
                data = unsorted.Next();
            }
            for (int i = middle; i < unsorted.Length; i++)
            {
                right.Add(data);
                if (unsorted.Length != left.Length + right.Length)
                {
                    data = unsorted.Next();
                }
            }

            left  = MergeSort(left);
            right = MergeSort(right);
            return(Merge(left, right));
        }
Example #3
0
        private static DataList Merge(DataList left, DataList right)
        {
            DataList result;

            if (left.GetType() == typeof(MyDataList))
            {
                result = new MyDataList();
            }
            else
            {
                result = new MyFileList();
            }

            while (left.Length > 0 || right.Length > 0)
            {
                if (left.Length > 0 && right.Length > 0)
                {
                    if (left.First() <= right.First())
                    {
                        result.Add(left.First());
                        left.RemoveFirst();
                    }
                    else
                    {
                        result.Add(right.First());
                        right.RemoveFirst();
                    }
                }
                else if (left.Length > 0)
                {
                    result.Add(left.First());
                    left.RemoveFirst();
                }
                else if (right.Length > 0)
                {
                    result.Add(right.First());

                    right.RemoveFirst();
                }
            }
            return(result);
        }
Example #4
0
        public static void Test_Array_List_Comparison_File(int seed, int n)
        {
            Stopwatch   watch   = new Stopwatch();
            MyFileArray myarray = new MyFileArray("testasArray.dat", n, seed);

            watch.Start();
            MyFileArray MySortedArray = (MyFileArray)MergeSort(myarray);

            watch.Stop();
            var        arrayTime = watch.Elapsed;
            MyFileList mylist    = new MyFileList("testasList.dat", n, seed);

            watch.Start();
            MyFileList MySortedList = (MyFileList)MergeSort(mylist);

            watch.Stop();
            var listTime = watch.Elapsed;

            Console.WriteLine("{0, -10} {1, -20}  {2, -20}", n, arrayTime, listTime);
        }