Пример #1
0
        public static void VirtualStacks()
        {
            ShowHeader();

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

            // Reads poems into memory at their standard locations (page 9, page 29, page 399)
            Week_2_Class.PoemReader();

            // Tests if the last page (i.e. the stack area) is empty via serial search; writes first non-empty location and prompts user to close program if it's not empty
            IsStackEmpty();

            // Setting this to true makes the VirtualStackPush method initialize stack pointers to appropriate pushing positions
            // Since the last page is stack area, that is: [499, 0, 0] for current, bottom, top, and [499, 0, 1] for next.
            wasPopping = true;

            // Calls the logging method and sends necessary args (logType, addToName) to name the log and determine whether to pop or push
            StackLogger("InitPush", "Stack");

            // Calls the logging method again, this time popping the stack clean
            StackLogger("Pop", "Stack");

            // Calls the logging method again, this time pushing the reversed poem first lines to the stack
            StackLogger("Push", "InverseStack");

            // Calls the logging method one last time, this time popping the stack clean - and setting the poem's first lines back in original order
            StackLogger("Pop", "InverseStack");
        }
Пример #2
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);
        }
Пример #3
0
        public static void SerializedSearch()
        {
            ShowHeader();

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

            // Reads the poems into memory, but does not write them to console - that was split into Week_2_Class.PoemWriter()
            Week_2_Class.PoemReader();

            // Searches and writes log file based on search performed, creates "C:\devel\Logs\" directory if it does not exist
            CreateSearchLog(serializedSearch, blank, "find_virtualNulls");

            // Asks if they'd like to search again, sends back to search choice method if yes
            if (YesNo("Would you like to search again"))
            {
                ChooseSearch();
            }
        }
Пример #4
0
        public static void FindUppercaseT()
        {
            ShowHeader();

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

            // Reads the poems into memory, but does not write them to console - that was split into Week_2_Class.PoemWriter()
            Week_2_Class.PoemReader();

            // Finds a blank page and puts my name into memory on that page
            RememberMe();

            // Calls CreateSearchLog method with appropriate args for searchType, searchQuery, and addToName strings
            // Searches virtualMemory and writes log file based on search performed, creates "C:\devel\Logs\" directory if it does not exist
            // Since I'm sending "T" for searchQuery, will find all instances of 'T' and set pointers for their locations
            // Then sends total number of 'T' found to ConvertTtoQ() method
            CreateSearchLog(serializedSearch, "T", "find_T");
        }
Пример #5
0
        /// <summary>
        /// Use frequency sort to sort the poems and log the efficiency of the algorithm.
        /// </summary>
        public static void FrequencySortAndLog()
        {
            // 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 = Week_10_Class.GetPoemsInVirtualMemory();

            // Set log count to total poem array length, since part of this algorithm is loading the poems into the array.
            int logOneCount = allPoems.Length;

            // Round the length of allPoems down to nearest 100
            // Integer division always rounds down so by dividing by 100 then multiplying by 100 we get the value we want
            // Examples:
            // 5927 / 100 = 59.27; C# rounds int to 59; 59 * 100 = 5900
            // 5977 / 100 = 59.77; C# rounds int to 59; 59 * 100 = 5900
            int poemLengthDownToHundred = allPoems.Length / 100 * 100;

            // Frequency sort segment of size i
            // Increase log count by the number of operations performed by a segment sort of size 10
            // 255 represents the size of the frequency counters array (i.e. ASCII values 0-255); Parameter exists in case I want to frequency sort things other than ASCII
            logOneCount += FrequencySortSegment(allPoems, 10, 255);

            // Write a log file with a 1 for the value of logOneCount
            Week_10_Class.WriteEfficiencyLog(10, logOneCount, Common_Code.frequencySort);

            // Repeat above processes for segments of size 100, 200, 300...5900, then size allPoems.Length
            for (int i = 100;
                 i <= allPoems.Length;
                 i = i < poemLengthDownToHundred ? (i + 100) : allPoems.Length)
            {
                // Set log count to total poem array length, since part of this algorithm is loading the poems into the array.
                logOneCount = allPoems.Length;

                // Frequency sort a segment of allPoems, segment size: i (100, 200, 300, etc)
                // Increase log count by the number of operations performed by that sort
                logOneCount += FrequencySortSegment(allPoems, i, 255);

                // Write a log file with a 1 for the value of logOneCount
                Week_10_Class.WriteEfficiencyLog(i, logOneCount, Common_Code.frequencySort);

                // Break out of loop if i == allPoems.Length, otherwise infinite loop
                if (i == allPoems.Length)
                {
                    break;
                }

                // Expanded version of above ? : ternary operation (in for() loop iterator)
                //if (i < poemLengthDownToHundred)
                //{
                //    i += 100;
                //}
                //else
                //{
                //    i = allPoems.Length;
                //}
            }

            // Open the log folder path given in Common_Code.logDir in explorer
            Common_Code.OpenLogFolder();
        }
Пример #6
0
        /// <summary>
        /// Prompts the user to select which section (week) to run
        /// </summary>
        /// <remarks>Week input do-while loop had a bug almost the whole semester where it wasn't actually doing anything because I used && (AND) instead of || (OR). Whoops.</remarks>
        private static void WeekSelect()
        {
            // Tests input for valid integers (1 through 16), asks again if input is invalid
            var weekInput = 0;

            do
            {
                Common_Code.CenterWrite("Enter class week (1 to 16)");
                var input = Console.ReadLine();
                int.TryParse(input, out weekInput);
            } while ((weekInput <= 0) || (weekInput > 16));

            var labWeek = string.Format("Week {0} was a lab week. Please choose a different week.", weekInput);

            var futureWeek = string.Format("We aren't at week {0} yet. Please choose a different week.", weekInput);

            // Sends user to Week_#_Class.Method based on input, restarts WeekSelect method if incorrect input
            // Defaults to restarting WeekSelect method
            switch (weekInput)
            {
            case 1:
                Week_1_Class.TextToASCIIdec();
                break;

            case 2:
                Week_2_Class.PoemReadWrite();
                break;

            case 3:
                // Sends user to choose which search method to use
                // Figure we might implement more searches later on down the line
                // Can just point back to this case for those weeks
                Common_Code.ChooseSearch();
                break;

            case 4:
                Console.WriteLine(labWeek);
                WeekSelect();
                break;

            case 5:
                Week_5_Class.FindUppercaseT();
                break;

            case 6:
                Week_6_Class.VirtualStacks();
                break;

            case 7:
                goto case 4;

            case 8:
                Week_8_Class.VirtualQueue();
                break;

            case 9:
                goto case 4;

            case 10:
                // Create new instance of Week_10_Class and start the BubbleSortAndLog method from that class
                var week_10 = new Week_10_Class();
                week_10.BubbleSortAndLog();
                break;

            case 11:
                Week_11_Class.FrequencySortAndLog();
                break;

            case 12:
                goto case 16;

            case 13:
                goto case 16;

            case 14:
                goto case 16;

            case 15:
                goto case 16;

            case 16:
                Week_12_Class.SortComparisons();
                break;

            default:
                Console.WriteLine("Entered {0} week, ended in default case - please select a valid week", weekInput);
                WeekSelect();
                break;
            }
        }