Example #1
0
        private void btnStack_Click(object sender, EventArgs e) //STACK BUTTON
        {
            //Declaring a new instance of Stacks and displaying properties to the Windows Form
            Stack1 stack1 = new Stack1();

            richTextBox2.AppendText(stack1.AccessTime + "        ");
            richTextBox2.AppendText(stack1.SearchTime + "\n");
            richTextBox2.AppendText(stack1.InsertTime + "        ");
            richTextBox2.AppendText(stack1.DeleteTime + "\n");
            richTextBox2.AppendText(stack1.SpaceComplexity + "\n");
            richTextBox2.AppendText("*All Big-O values represent worst-case scenarios unless otherwise noted");

            //Displaying the Advantages and Disadvantages of Stacks to the Windows Form
            richTextBox1.AppendText("STACK: \n");
            richTextBox1.AppendText(stack1.Advantages("A stack stores data in the same way that arrays do—it’s simply a list of elements." +
                                                      "A stack uses LIFO (last -in first -out) ordering.\n" +
                                                      "It uses the following operations:\n" +
                                                      "   -pop(): Remove the top item from the stack.\n" +
                                                      "   -push(item): Add an item to the top of the stack.\n" +
                                                      "   -peek(): return the top of the stack.\n" +
                                                      "   -isEmpty(): Return true if and only if the stack is empty.\n" +
                                                      "Stacks are useful in certain recursive algorithms.  And allows constant time adds and removes."));
            richTextBox1.AppendText("\n\n");
            richTextBox1.AppendText(stack1.Disadvantages("Disadvantages of a stack: \n" +
                                                         "   -Stack memory is very limited.\n" +
                                                         "   -Creating too many objects on the stacks can increase the risk of stack overflow. \n" +
                                                         "   -Random access is not possible. \n" +
                                                         "   -Variable storage will be overwritten, which sometimes leads to undefined behavior of the function or program."));

            //Displaying extra notes from a rich text file in the bin
            using (StreamReader Reader = new StreamReader(@"C:\Users\Clayt\source\repos\CSC205\CSC205_StudyProject\CSC205_StudyProject\bin\Stack.rtf"))
            {
                while (!Reader.EndOfStream)
                {
                    richTextBox5.AppendText(Reader.ReadLine());
                }
            }
        }