コード例 #1
0
        /// <summary>
        /// Övning 1: ExamineList()
        ///
        /// Examines the datastructure List
        ///
        /// Svar på frågor
        /// När ökar listans kapacitet? (Alltså den underliggande arrayens storlek)
        ///     Listans kapacitet ökas när man når nuvarande kapacitet
        ///
        /// Med hur mycket ökar kapaciteten?
        /// Storleken på listan dubblas
        ///
        /// Varför ökar inte listans kapacitet i samma takt som element läggs till?
        ///     Det skulle leda till att listan måste allokeras om för varje element som läggs till. Ger dålig prestanda
        ///
        /// Minskar kapaciteten när element tas bort ur listan?
        ///     Nej
        ///
        /// När är det då fördelaktigt att använda en egendefinierad array istället för en lista?
        ///     Om man vet hur många elemet som skall lagras i arrayen och att man inte ändrar antalet element i arrayen
        ///
        /// </summary>
        static void ExamineList()
        {
            Console.WriteLine("ExamineList");

            /*
             * Loop this method untill the user inputs something to exit to main menue.
             * Create a switch statement with cases '+' and '-'
             * '+': Add the rest of the input to the list (The user could write +Adam and "Adam" would be added to the list)
             * '-': Remove the rest of the input from the list (The user could write -Adam and "Adam" would be removed from the list)
             * In both cases, look at the count and capacity of the list
             * As a default case, tell them to use only + or -
             * Below you can see some inspirational code to begin working.
             */

            //List<string> theList = new List<string>();
            //string input = Console.ReadLine();
            //char nav = input[0];
            //string value = input.substring(1);

            //switch(nav){...}

            ExamineList examineList = new ExamineList();

            examineList.RunExamineList();
        }
コード例 #2
0
        /// <summary>
        /// Examines the datastructure List
        /// </summary>
        static void ExamineList()
        {
            /*
             * Loop this method untill the user inputs something to exit to main menue.
             * Create a switch statement with cases '+' and '-'
             * '+': Add the rest of the input to the list (The user could write +Adam and "Adam" would be added to the list)
             * '-': Remove the rest of the input from the list (The user could write -Adam and "Adam" would be removed from the list)
             * In both cases, look at the count and capacity of the list
             * As a default case, tell them to use only + or -
             * Below you can see some inspirational code to begin working.
             */

            // Question 1: When the count is equals to its capacity.
            // Question 2: It doubles the current capacity.
            // Question 3: It only allocates more memory when count exceeds its capacity.
            // Question 4: No it does not. It needs a Trim method to scale down the capacity.
            // Question 5: When you know the number of elements needed.

            Console.Clear();

            ExamineList examine = new ExamineList();
            bool        quit    = false;

            do
            {
                ExamineListInfo();

                char input = InputCheck();

                switch (input)
                {
                case '+':
                    Console.WriteLine("Add names to the list");
                    examine.AddToList();

                    Console.Clear();
                    break;

                case '-':
                    Console.WriteLine("Remove names from the list");
                    examine.RemoveFromList();

                    Console.Clear();
                    break;

                case 'Q':
                    Console.Clear();
                    quit = true;
                    break;

                default:
                    Console.WriteLine("Not a valid command");
                    break;
                }
            } while (!quit);
        }