예제 #1
0
        public void ModifyCustomList(string[] inputArgs)
        {
            string command = inputArgs[0].ToLower();
            string element = string.Empty;
            int    index   = 0;

            switch (command)
            {
            case "add":
                element = inputArgs[1];
                customList.Add(element);
                break;

            case "remove":
                index = int.Parse(inputArgs[1]);
                customList.Remove(index);
                break;

            case "contains":
                element = inputArgs[1];
                bool isContains = customList.Contains(element);
                Console.WriteLine(isContains);
                break;

            case "swap":
                int firstIndex  = int.Parse(inputArgs[1]);
                int secondIndex = int.Parse(inputArgs[2]);
                customList.Swap(firstIndex, secondIndex);
                break;

            case "greater":
                element = inputArgs[1];
                int count = customList.CountGreaterThan(element);
                Console.WriteLine(count);
                break;

            case "max":
                string maxElement = customList.Max();
                Console.WriteLine(maxElement);
                break;

            case "min":
                string minElement = customList.Min();
                Console.WriteLine(minElement);
                break;

            case "print":
                Console.WriteLine(customList);
                break;

            default:
                throw new InvalidOperationException("Invalid command!");
            }
        }
예제 #2
0
    private static void ExecuteCommand(ICustomList <string> customList, string command)
    {
        var commandArgs = command.Split(' ');
        var commandName = commandArgs[0];
        var args        = commandArgs.Skip(1).ToArray();

        switch (commandName)
        {
        case "Add":
            customList.Add(args[0]);
            break;

        case "Remove":
            customList.Remove(int.Parse(args[0]));
            break;

        case "Contains":
            Console.WriteLine(customList.Contains(args[0]));
            break;

        case "Swap":
            customList.Swap(int.Parse(args[0]), int.Parse(args[1]));
            break;

        case "Greater":
            Console.WriteLine(customList.CountGreaterThan(args[0]));
            break;

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

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

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

        case "Sort":
            customList.Sort();
            break;

        default:
            break;
        }
    }
예제 #3
0
    private static void Execute(string command, ICustomList <string> myList)
    {
        var commandArgs = command.Split();

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

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

        case "Contains":
            Console.WriteLine(myList.Contains(commandArgs[1]));
            break;

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

        case "Greater":
            Console.WriteLine(myList.CountGreaterThan(commandArgs[1]));
            break;

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

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

        case "Print":
            Console.WriteLine(string.Join(Environment.NewLine, myList));
            break;

        case "Sort":
            myList.Sort();
            break;

        default:
            break;
        }
    }
예제 #4
0
 public bool Contains(T item)
 {
     return(List.Contains(item));
 }
 public override void Execute(string[] inputParameters, ICustomList <string> listOfItems)
 {
     this.writer.WriteLine(listOfItems.Contains(inputParameters[1]));
 }