Exemple #1
0
        public static void Main()
        {
            MyCustomList <string> elements = new MyCustomList <string>();

            string command = Console.ReadLine();

            while (command != "END")
            {
                string[] commandArgs = command.Split(' ');

                switch (commandArgs[0])
                {
                case "Add": elements.Add(commandArgs[1]); break;

                case "Remove": elements.Remove(int.Parse(commandArgs[1])); break;

                case "Contains": elements.Contains(commandArgs[1]); break;

                case "Swap": elements.Swap(int.Parse(commandArgs[1]), int.Parse(commandArgs[2])); break;

                case "Greater": elements.CountGreaterThan(commandArgs[1]); break;

                case "Max": elements.Max(); break;

                case "Min": elements.Min(); break;

                case "Print": elements.Print(); break;
                }
            }
        }
Exemple #2
0
        public static MyCustomList <T> operator -(MyCustomList <T> myList, MyCustomList <T> myListTwo)
        {
            MyCustomList <T> results = new MyCustomList <T>();

            results = myList;
            foreach (T item in myListTwo)
            {
                results.Remove(item);
            }
            return(results);
        }
        public void InterpredCommand(string input)
        {
            var tokens  = input.Split(' ');
            var command = tokens[0];

            switch (command)
            {
            case "Add":
                var element = tokens[1];
                myList.Add(element);
                break;

            case "Remove":
                var index = int.Parse(tokens[1]);
                myList.Remove(index);
                break;

            case "Contains":
                element = tokens[1];
                Console.WriteLine(myList.Contains(element));
                break;

            case "Swap":
                var firstIndex  = int.Parse(tokens[1]);
                var secondIndex = int.Parse(tokens[2]);
                myList.Swap(firstIndex, secondIndex);
                break;

            case "Greater":
                element = tokens[1];
                Console.WriteLine(myList.CountGreaterElements(element));
                break;

            case "Max":
                Console.WriteLine(myList.Max());
                break;

            case "Min":
                Console.WriteLine(myList.Min());
                break;

            case "Print":
                Console.WriteLine(myList.Print());
                break;

            case "Sort":
                myList.Sort();
                break;
            }
        }
Exemple #4
0
        public static MyCustomList <T> operator-(MyCustomList <T> load1, MyCustomList <T> load2)
        {
            //MyCustomList<int> unload1 = new MyCustomList<int>() { 5, 15, 25, 35, 45 };
            //MyCustomList<int> unload2 = new MyCustomList<int>() { 10, 20, 30, 40, 50 };
            //MyCustomList<int> result = unload1 - unload2;
            MyCustomList <T> result = new MyCustomList <T>();

            for (int i = 0; i < load1.count; i++)
            {
                result.Remove(load1[i]);
            }

            return(result);
        }