示例#1
0
        public static void D_Sort_Speed_Test(int seed)
        {
            Console.WriteLine(" Speed Test D ");
            Console.WriteLine("\n Selection sort ARRAY: \n");
            int[]  length  = { 400, 800, 1600, 3200, 6400 };
            int[]  length2 = { 400, 800, 1600, 3200, 6400 };
            int[]  length3 = { 100, 200, 400 };
            string fileName;

            fileName = @"mydataaray.dat";
            string fileName2 = @"mydataaray2.dat";
            string filename3 = @"mydatalist.dat";

            for (int i = 0; i < length3.Length; i++)
            {
                MyFileArray n = new MyFileArray(fileName, length3[i], seed);
                using (n.fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
                {
                    Stopwatch t = new Stopwatch();
                    t.Start();
                    n.SelectionSort();
                    t.Stop();
                    TimeSpan e = t.Elapsed;
                    Console.WriteLine("Amount of data {0,5} --->>> Time elapsed: {1}", length3[i], e.ToString());
                }
            }
            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("\n Quick sort ARRAY \n");
            for (int i = 0; i < length2.Length; i++)
            {
                MyFileArray n = new MyFileArray(fileName2, length2[i], seed);
                using (n.fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
                {
                    Stopwatch t = new Stopwatch();
                    t.Start();
                    n.QuickSort();
                    t.Stop();
                    TimeSpan e = t.Elapsed;
                    Console.WriteLine("Amount of data {0,5} --->>> Time elapsed: {1}", length2[i], e.ToString());
                }
            }

            Console.WriteLine("------------------------------------------------------");
            Console.WriteLine("\n Selection sort LIST \n");
            for (int i = 0; i < length3.Length; i++)
            {
                MyFileList n = new MyFileList(filename3, length3[i], seed);
                using (n.fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
                {
                    Stopwatch t = new Stopwatch();
                    t.Start();
                    Selection_Sort_List(n);
                    t.Stop();
                    TimeSpan e = t.Elapsed;
                    Console.WriteLine("Amount of data {0,5} --->>> Time elapsed: {1}", length3[i], e.ToString());
                }
            }
        }
示例#2
0
        public static void Test_List_D(int seed)
        {
            int        n          = 12;
            string     filename   = @"mydatalist.dat";
            MyFileList myfilelist = new MyFileList(filename, n, seed);

            using (myfilelist.fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite))
            {
                Console.WriteLine("\n Selection sort LIST \n");
                myfilelist.Print(n);
                Selection_Sort_List(myfilelist);
                myfilelist.Print(n);
            }
            Console.WriteLine();
            Console.WriteLine("____________________________________________________________");
            Console.WriteLine("____________________________________________________________");
        }
示例#3
0
 public static void Selection_Sort_List(MyFileList list)
 {
     for (int i = 0; i < list.Length; i++)
     {
         int min    = i;
         int minVal = list.GetNode(i);
         for (int j = i + 1; j < list.Length; j++)
         {
             int tempVal = list.GetNode(j);
             if (tempVal < minVal)
             {
                 min    = j;
                 minVal = tempVal;
             }
         }
         int iVal = list.GetNode(i);
         list.Set2(minVal);
         list.GetNode(min);
         list.Set2(iVal);
     }
 }