Esempio n. 1
0
        public static void Test_File_Array_List(int seed)
        {
            int    n = 10;
            string filename;

            filename = @"mydataarraytest.txt";
            //filename = @"mydataarray.dat";
            MyFileArray myfilearray = new MyFileArray(filename, n);

            using (myfilearray.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n FILE ARRAY \n");
                myfilearray.Print(n);
                Radix_Sort(myfilearray);
                myfilearray.Print(n);
            }
            filename = @"mydatalisttest.txt";
            MyFileList myfilelist = new MyFileList(filename, n);

            using (myfilelist.fs = new FileStream(filename, FileMode.Open,
                                                  FileAccess.ReadWrite))
            {
                Console.WriteLine("\n FILE LIST \n");
                myfilelist.Print(n);
                Radix_Sort(myfilelist, seed);
                myfilelist.Print(n);
            }
        }
Esempio n. 2
0
        public static void Test_List_Radix_Sort_File(int n)
        {
            string filename;

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

            using (myfilelist.fs = new FileStream(filename, FileMode.Open,
                                                  FileAccess.ReadWrite))
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                Radix_Sort(myfilelist, n);
                watch.Stop();
                Console.WriteLine(string.Format("{0, -10} {1, -10}", n, watch.Elapsed.TotalMilliseconds));
            }
        }
Esempio n. 3
0
        public static void Counting_Sort(DataList items, int exp, int seed)
        {
            string resultsFile = "results.dat";
            string countFile   = "count.dat";
            int    n           = items.Length;

            MyFileList results = new MyFileList(n, resultsFile);
            MyFileList count   = new MyFileList(n, countFile);

            using (count.fs = new FileStream(countFile, FileMode.Open, FileAccess.ReadWrite))
            {
                using (results.fs = new FileStream(resultsFile, FileMode.Open, FileAccess.ReadWrite))
                {
                    int temp;
                    var current = items.Head();
                    while (current != 0)
                    {
                        current = current / exp % 10;
                        count.Set(current, count.Value(current) + 1);
                        current = items.Next();
                    }

                    for (int i = 1; i < 10; i++)
                    {
                        count.Set(i, count.Value(i) + count.Value(i - 1));
                    }

                    for (int i = n - 1; i >= 0; i--)
                    {
                        temp = items.Value(i) / exp % 10;
                        results.Set(count.Value(temp) - 1, items.Value(i));
                        count.Set(temp, count.Value(temp) - 1);
                    }
                    items.OverWrite(results);
                }
            }
        }