Beispiel #1
0
        public static void SortElements(CustomList <string> list)
        {
            CustomList <string> tempList = new CustomList <string>();

            var numberOfElements = list.Values.Count;

            for (int i = 0; i < numberOfElements; i++)
            {
                var minElement = list.Values[0];
                foreach (var value in list.Values)
                {
                    if (value.CompareTo(minElement) < 0)
                    {
                        minElement = value;
                    }
                }
                tempList.AddElement(minElement);
                list.Values.Remove(minElement);
            }

            for (int i = 0; i < numberOfElements; i++)
            {
                list.AddElement(tempList[i]);
            }
        }
    static void Main(string[] args)
    {
        CustomList <string> customList = new CustomList <string>();

        var command = Console.ReadLine().Split(' ').ToArray();

        var    commandParts = command[0];
        string element;

        while (command[0] != "END")
        {
            switch (command[0])
            {
            case "Add":
                element = command[1];
                customList.AddElement(element);
                break;

            case "Remove":
                var index = int.Parse(command[1]);
                customList.RemoveElement(index);
                break;


            case "Contains":
                element = command[1];
                Console.WriteLine(customList.ContainsElement(element));
                break;

            case "Swap":
                var index1 = int.Parse(command[1]);
                var index2 = int.Parse(command[2]);
                customList.Swap(index1, index2);
                break;

            case "Greater":
                element = command[1];
                Console.WriteLine(customList.CountGreaterThan(customList.cList, element));
                break;

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

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

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

                break;
            }

            command = Console.ReadLine().Split(' ').ToArray();
        }
    }
        static void Main()
        {
            try
            {
                CustomList<int> list = new CustomList<int>();

                list.AddElement(1);
                list.AddElement(2);
                list.AddElement(3);
                list.AddElement(4);
                list.AddElement(5);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(15);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                list.AddElement(6);
                //list.AddElement(6);

                Console.WriteLine(list.Min());
                Console.WriteLine(list.Max());
                Console.WriteLine(list.IndexOf(15));
            }
            catch (InvalidOperationException ioe)
            {

                Console.WriteLine(ioe.Message);
            }
        }