示例#1
0
        /// <summary>
        /// Show header, initialize virtualMemory, bubble sort poems by incremented segments and log number of exchanges used by each sort
        /// </summary>
        public void BubbleSortAndLog()
        {
            // Shows a header in the console similar to the comment at the top of this file
            Common_Code.ShowHeader();

            // Initializes all virtualMemory locations to -99
            Common_Code.VirtualMemoryInit();

            // Reads all three of the poems (TCOTLB.txt, RC.txt, GEAH.txt) in textDir (C:\devel\TFiles\)
            Week_2_Class.PoemReader();

            // Search virtualMemory for the text of the poems and put it in an array
            int[] allPoems = GetPoemsInVirtualMemory();

            int totalPoemsLength = allPoems.Length;

            // Variable to track the number of exchanges used in a sort
            int exchanges;

            // Sort a segment of allPoems of size 10
            exchanges = BubbleSortSegment(allPoems, 10);

            // Write the log from the size 10 sort
            WriteEfficiencyLog(10, exchanges, Common_Code.bubbleSort);

            // Sort and log segments of the array starting at 100 and incrementing by 100 every time (100, 200, 300, etc) up to 2000
            for (int i = 100; i <= 2000; i += 100)
            {
                exchanges = BubbleSortSegment(allPoems, i);
                WriteEfficiencyLog(i, exchanges, Common_Code.bubbleSort);
            }

            bool keepSorting = Common_Code.YesNo("Keep sorting segments from size 2000 to 5927 (may take a few minutes)");

            if (keepSorting)
            {
                // Sort and log segments of the array starting at 2000 and incrementing by 100 every time (2000, 2100, 2200, etc) up to 5900
                for (int i = 2000; i <= totalPoemsLength; i += 100)
                {
                    exchanges = BubbleSortSegment(allPoems, i);
                    WriteEfficiencyLog(i, exchanges, Common_Code.bubbleSort);
                }

                // Sort the entire array
                exchanges = BubbleSort(allPoems);

                // Write the log for the full sort
                WriteEfficiencyLog(totalPoemsLength, exchanges, Common_Code.bubbleSort);
            }

            // Write all locations in the sortable source array to log file for debugging
            Common_Code.IntArrayLog(allPoems, "AllPoems");

            // Write all locations in virtual memory to log file for debugging
            Common_Code.VirtualMemoryLog(10, true);
        }
示例#2
0
        public static void TextToASCIIdec()
        {
            Common_Code.ShowHeader();

            var textDir = Common_Code.textDir;

            // Calls TFileSelect method to find what text file they want to use (in this case for conversion)
            var fileToConv = TFileSelect();

            // Appends "ConV" to filename based on chosen file, assigns result to newFile
            var newFile = "ConV" + fileToConv;

            // Confirmation of chosen file, option to restart method to choose new file; if they choose no (YesNo method returns false), restarts method
            Console.WriteLine("The contents of {0} will be read to ASCII decimal values\nValues will output to new file {1}", fileToConv, newFile);
            if (!Common_Code.YesNo("Is this ok?"))
            {
                TextToASCIIdec();
            }

            // Uses StreamReader.Read method to read one character at a time from the text file
            // Then uses StreamReader.WriteLine method to write ASCII decimal value for each character
            // Writes to a file with newFile variable as name, in the textDir folder
            using (var readChar = new StreamReader(textDir + fileToConv))
            {
                var currentChar = readChar.Read();
                using (var write = new StreamWriter(textDir + newFile))
                {
                    while (currentChar != -1)
                    {
                        write.WriteLine("{0}", currentChar);
                        currentChar = readChar.Read();
                    }
                }
            }

            // Tells user what it did, asks if they'd like to convert another file
            // If YesNo method returns true, restarts TextToASCIIdec method
            Console.WriteLine("Converted {0} to {1}", fileToConv, newFile);
            if (Common_Code.YesNo("Would you like to convert another file?"))
            {
                TextToASCIIdec();
            }
        }