Exemple #1
0
        static void Main(string[] args)
        {
            KargerMinCut();
            TestAssignment3();
            int[] testArray       = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
            int   comparisonCount = new QuickSorter().QuickSortAndCountComparisons(testArray, 0, testArray.Length - 1);

            int realCount = 45;

            //Assert.AreEqual(inversionCount, 8);

            ShouldSortLargeNumberOfItems();
        }
Exemple #2
0
        private static void CountComparisons()
        {
            string       fileName = "QuickSort.txt";
            StreamReader reader   = null;

            int[] testArray = null, testArrayCopy = null;


            try
            {
                if (File.Exists(fileName))
                {
                    var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    reader = new StreamReader(fileStream);
                    string   fullTextCSV = reader.ReadToEnd().Replace(Environment.NewLine, ",");
                    string[] stringArray = fullTextCSV.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    testArray     = stringArray.Select <string, int>(x => Convert.ToInt32(x)).ToArray <int>();
                    testArrayCopy = new Int32[testArray.Length];
                    testArray.CopyTo(testArrayCopy, 0);

                    int invs = new QuickSorter().QuickSortAndCountComparisons(testArray, 0, testArray.Length - 1);
                    Array.Sort <int>(testArrayCopy);

                    bool isSame = true;
                    for (int i = 0; i < testArray.Length; i++)
                    {
                        if (testArray[i] != testArrayCopy[i])
                        {
                            isSame = false;
                        }
                    }

                    if (isSame)
                    {
                        Console.WriteLine("succeeded");
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }