private static void Main(string[] args)
        {
            var tp        = new TextProcessor();
            var stopWatch = new Stopwatch();

            const string filename    = "Shakespeare.txt";
            const string regex       = @"[a-z]+'?-?[a-z]*";
            const bool   isSearching = false;

            // This is to find the text files - Without having a long path string.
            Directory.SetCurrentDirectory(Path.Combine(Environment.CurrentDirectory, @"../../../"));
            var path = $@"{Directory.GetCurrentDirectory()}\Data\{filename}";

            #region Sorting

            tp.ProcessTextFile(path, regex);
            stopWatch.Start();

            Trie.Sort(tp.ProcessedStrings);

            stopWatch.Stop();
            Console.WriteLine($"isSorted: {Utils.isSortedMin(tp.ProcessedStrings)}");
            Console.WriteLine($"Execution Time: {stopWatch.Elapsed} for sorting {tp.ProcessedStrings.Length} elements.\n");

            // Preventing showing the sorted Shakespeare.txt
            if (!filename.Equals("Shakespeare.txt"))
            {
                foreach (var words in tp.ProcessedStrings)
                {
                    Console.Write($"{words} ");
                }
            }

            #endregion


            #region Searching

            if (isSearching)
            {
                stopWatch.Reset();
                const string target = "z";
                stopWatch.Start();

                //var search = Binary.Search(tp.ProcessedStrings, target, 0, tp.ProcessedStrings.Length - 1);
                var search = Exponential.Search(tp.ProcessedStrings, target, tp.ProcessedStrings.Length - 1);

                stopWatch.Stop();
                Console.WriteLine($"\n\nTarget: \"{target}\" is located at index: {search}.");
                Console.WriteLine(
                    $"Execution Time: {stopWatch.Elapsed} for searching \"{target}\" in {tp.ProcessedStrings.Length} elements.\n");
            }

            #endregion
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var textProcessor = new TextProcessor();
            var regexPattern  = @"[a-zA-ZæøåÆØÅ]+'?-?[a-zA-ZæøåÆØÅ]*";

            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            var dataLength = textProcessor.ProcessedStrings.Length;

            var stopwatch = Stopwatch.StartNew();


            #region Selection Sort

            // Take the first 10.000 elements from the original array
            var sampleData = textProcessor.ProcessedStrings.Take(10000).ToArray();
            Selection.Sort(sampleData);
            stopwatch.Stop();
            PrintElapsedTime(sampleData.Length, stopwatch.ElapsedMilliseconds, "Selection Sort");

            #endregion

            #region Insertion sort

            sampleData = textProcessor.ProcessedStrings.Take(10000).ToArray();
            stopwatch  = Stopwatch.StartNew();
            Insertion.Sort(sampleData);
            stopwatch.Stop();
            PrintElapsedTime(sampleData.Length, stopwatch.ElapsedMilliseconds, "Insertion Sort");

            #endregion

            #region Merge Sort

            stopwatch = Stopwatch.StartNew();
            Merge.Sort(textProcessor.ProcessedStrings);
            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Merge Sort");

            #endregion

            #region Heap Sort

            // Read the file again so the array is back in it's original state
            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            stopwatch = Stopwatch.StartNew();
            ArraySorter <string> .SortAscending(textProcessor.ProcessedStrings);

            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Heap Sort");

            #endregion

            #region Trie Sort

            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            stopwatch = Stopwatch.StartNew();
            Trie.Sort(textProcessor.ProcessedStrings);
            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Trie");

            #endregion
        }