Пример #1
0
        public static void menu()
        {
            char        c;
            string      name;
            StringArray myArray = new StringArray();

            Console.WriteLine("Choose from the following options:" + "\n" + "\n" +
                              "(I)nsert" + "\n" + "(D)elete" + "\n" + "Display (A)ll" + "\n" + "(Q)uit");
            c = Console.ReadLine()[0];
            c = Char.ToUpper(c);
            while (c != 'Q')
            {
                while (c != 'N')
                {
                    if (c == 'I')
                    {
                        while (c != 'N')
                        {
                            Console.Clear();
                            Console.Write("Enter a name: ");
                            name = Console.ReadLine();
                            myArray.insertion(name);
                            Console.Write("Continue? (Y)/(N)");
                            c = Console.ReadLine()[0];
                            c = Char.ToUpper(c);
                        }
                    }
                    else if (c == 'D')
                    {
                        int search;
                        Console.Clear();
                        Console.WriteLine("Enter name for deletion: ");
                        name   = Console.ReadLine();
                        search = myArray.findString(name);
                        myArray.del(search);
                        c = 'N';
                    }
                    else if (c == 'A')
                    {
                        Console.Clear();
                        myArray.PrintArray();
                        Console.ReadLine();
                        c = 'N';
                    }
                }
                Console.Clear();
                Console.WriteLine("Choose from the following options:" + "\n" + "\n" +
                                  "(I)nsert" + "\n" + "(D)elete" + "\n" + "Display (A)ll" + "\n" + "(Q)uit");
                c = Console.ReadLine()[0];
                c = Char.ToUpper(c);
            }
        }
Пример #2
0
        public static void demoSortingInput()
        {
            StringArray myArray = new StringArray();
            string      name;

            Console.Write("Enter a name ('quit' to stop': ");
            name = Console.ReadLine();
            while (name != "quit")
            {
                myArray.add(name);
                Console.Write("Enter a name ('quit' to stop': ");
                name = Console.ReadLine();
            }

            myArray.BubbleSort();
            myArray.PrintArray();
        }
Пример #3
0
        public static void demoStringSort()
        {
            string      cat;
            int         ndx;
            StringArray myArray = new StringArray();

            myArray.add("Tegan");
            myArray.add("Alystra");
            myArray.add("Brandon");
            myArray.add("Oliver");
            myArray.add("Casey");
            myArray.add("Midnight");
            myArray.add("Jeremiah");
            myArray.add("Maya");

            myArray.BubbleSort();
            myArray.PrintArray();
            cat = "Midnight";
            ndx = myArray.findString(cat);
            Console.WriteLine("{0} found at index: {1}", cat, ndx);
        }
Пример #4
0
        public static void demoSortingInput()
        {
            StringArray myArray = new StringArray();
            string name;
            Console.Write("Enter a name ('quit' to stop': ");
            name = Console.ReadLine();
            while (name != "quit")
            {
                myArray.add(name);
                Console.Write("Enter a name ('quit' to stop': ");
                name = Console.ReadLine();
            }

            myArray.BubbleSort();
            myArray.PrintArray();
        }
Пример #5
0
        public static void demoInsertDelete()
        {
            StringArray myArray = new StringArray();
            Console.Write(
                "Please make a selection:\n" +
                "1. Insert\n" +
                "2. Delete\n" +
                "3. Display All\n" +
                "4. Quit\n"
            );

            short selection = getMenuSelection();
            while (selection != 4)
            {
                switch (selection)
                {
                    case 1:
                    {
                        Console.Write("What name would you like to insert?\n");
                        string name = Console.ReadLine();
                        myArray.insert(name);
                        break;
                    }
                    case 2:
                    {
                        Console.Write("What name would you like to delete?\n");
                        string name = Console.ReadLine();
                        int index = myArray.binarySearch(name);
                        if (index > 0)
                        {
                            myArray.delete(Math.Abs(index));
                        }
                        else
                        {
                            // Not found...
                            Console.Write("Could not find {0} in array!\n", name);
                        }
                        break;
                    }
                    case 3:
                    {
                        myArray.PrintArray();
                        break;
                    }
                    default:
                    {
                        Console.Write(
                            "Invalid selection! Please choose one of the following:\n" +
                            "1. Insert\n" +
                            "2. Delete\n" +
                            "3. Display All\n" +
                            "4. Quit\n"
                        );

                        break;
                    }
                }
                Console.Write("Please make another selection:\n");
                selection = getMenuSelection();
            }
        }
Пример #6
0
        public static void demoStringSort()
        {
            string cat;
            int ndx;
            StringArray myArray = new StringArray();
            myArray.add("Tegan");
            myArray.add("Alystra");
            myArray.add("Brandon");
            myArray.add("Oliver");
            myArray.add("Casey");
            myArray.add("Midnight");
            myArray.add("Jeremiah");
            myArray.add("Maya");

            myArray.BubbleSort();
            myArray.PrintArray();
            cat = "Midnight";
            ndx = myArray.binarySearch(cat);

            string name = "Branford";
            int insertionPoint = myArray.binarySearch(name);
            Console.WriteLine("Should insert {0} at {1}", name, insertionPoint);
            Console.WriteLine("{0} found at index: {1}", cat, ndx);
        }