static void Main()
        {
            string[]            elementsToAdd       = Console.ReadLine().Split();
            int                 countOfRemoveOps    = int.Parse(Console.ReadLine());
            AddCollection       addCollection       = new AddCollection();
            AddRemoveCollection addRemoveCollection = new AddRemoveCollection();
            MyList              myList = new MyList();

            foreach (var elementToAdd in elementsToAdd)
            {
                Console.Write(addCollection.Add(elementToAdd) + " ");
            }
            Console.WriteLine();
            foreach (var elementToAdd in elementsToAdd)
            {
                Console.Write(addRemoveCollection.Add(elementToAdd) + " ");
            }
            Console.WriteLine();
            foreach (var elementToAdd in elementsToAdd)
            {
                Console.Write(myList.Add(elementToAdd) + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < countOfRemoveOps; i++)
            {
                Console.Write(addRemoveCollection.Remove() + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < countOfRemoveOps; i++)
            {
                Console.Write(myList.Remove() + " ");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string[]   data                = Console.ReadLine().Split();
            IAdd       addcollection       = new AddCollection();
            IAddRemove addRemoveCollection = new AddRemoveCollection();
            IMyList    mylist              = new MyList();
            List <int> result              = new List <int>();
            List <int> result1             = new List <int>();
            List <int> result2             = new List <int>();

            foreach (var item in data)
            {
                result.Add(addcollection.Add(item));
                result1.Add(addRemoveCollection.Add(item));
                result2.Add(mylist.Add(item));
            }
            Console.WriteLine(string.Join(" ", result));
            Console.WriteLine(string.Join(" ", result1));
            Console.WriteLine(string.Join(" ", result2));
            int           n = int.Parse(Console.ReadLine());
            List <string> a = new List <string>();
            List <string> b = new List <string>();

            for (int i = 0; i < n; i++)
            {
                a.Add((addRemoveCollection.Remove()));
                b.Add((mylist.Remove()));
            }
            Console.WriteLine(string.Join(" ", a));
            Console.WriteLine(string.Join(" ", b));
        }
Example #3
0
        static void Main()
        {
            IAddCollection       addCollection       = new AddCollection();
            IAddRemoveCollection addRemoveCollection = new AddRemoveCollection();
            IMyList    myList      = new MyList();
            List <int> outputLine1 = new List <int>();
            List <int> outputLine2 = new List <int>();
            List <int> outputLine3 = new List <int>();

            string[] input = Console.ReadLine().Split();
            for (int i = 0; i < input.Length; i++)
            {
                outputLine1.Add(addCollection.AddItem(input[i]));
                outputLine2.Add(addRemoveCollection.AddItem(input[i]));
                outputLine3.Add(myList.AddItem(input[i]));
            }
            int           removedOperations = int.Parse(Console.ReadLine());
            List <string> outputLine4       = new List <string>();
            List <string> outputLine5       = new List <string>();

            for (int i = 0; i < removedOperations; i++)
            {
                outputLine4.Add(addRemoveCollection.RemoveItem());
                outputLine5.Add(myList.RemoveItem());
            }
            foreach (var item in outputLine1)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();
            foreach (var item in outputLine2)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();
            foreach (var item in outputLine3)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();
            foreach (var item in outputLine4)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();
            foreach (var item in outputLine5)
            {
                Console.Write($"{item} ");
            }
        }
Example #4
0
        public static void Main(string[] args)
        {
            var itemsToAdd = Console.ReadLine().Split().ToArray();

            int removeOperations = int.Parse(Console.ReadLine());

            AddCollection       addCollection       = new AddCollection();
            AddRemoveCollection addRemoveCollection = new AddRemoveCollection();
            MyList myList = new MyList();

            foreach (var item in itemsToAdd)
            {
                Console.Write($"{addCollection.Add(item)} ");
            }

            Console.WriteLine();

            foreach (var item in itemsToAdd)
            {
                Console.Write($"{addRemoveCollection.Add(item)} ");
            }

            Console.WriteLine();

            foreach (var item in itemsToAdd)
            {
                Console.Write($"{myList.Add(item)} ");
            }
            Console.WriteLine();

            for (int i = 0; i < removeOperations; i++)
            {
                Console.Write($"{addRemoveCollection.Remove()} ");
            }

            Console.WriteLine();

            for (int i = 0; i < removeOperations; i++)
            {
                Console.Write($"{myList.Remove()} ");
            }
        }
        static void Main(string[] args)
        {
            IAddCollection <string>       addCollection       = new AddCollection <string>();
            IAddRemoveCollection <string> addRemoveCollection = new AddRemoveCollection <string>();
            IMyList <string> myList = new MyList <string>();

            var elements = Console.ReadLine()
                           .Split(" ");

            var removeOperations = int.Parse(Console.ReadLine());

            AddMethod(addCollection, elements);

            AddMethod(addRemoveCollection, elements);

            AddMethod(myList, elements);

            RemoveMethod(addRemoveCollection, removeOperations);

            RemoveMethod(myList, removeOperations);
        }
Example #6
0
        public static void Main()
        {
            string[] elementsToAdd    = Console.ReadLine().Split();
            int      countOfRemoveOps = int.Parse(Console.ReadLine());

            AddCollection       addCollection       = new AddCollection();
            AddRemoveCollection addRemoveCollection = new AddRemoveCollection();
            MyList myList = new MyList();

            printIndexs(elementsToAdd, addCollection, addRemoveCollection, myList);
            Console.WriteLine();
            for (int i = 0; i < countOfRemoveOps; i++)
            {
                Console.Write(addRemoveCollection.Remove() + " ");
            }
            Console.WriteLine();
            for (int i = 0; i < countOfRemoveOps; i++)
            {
                Console.Write(myList.Remove() + " ");
            }
            Console.WriteLine();
        }
Example #7
0
        static void Main(string[] args)
        {
            var addCollection       = new AddCollection();
            var addRemoveCollection = new AddRemoveCollection();
            var myList = new MyList();

            var itemsToAdd            = new List <string>(Console.ReadLine().Split());
            var numberOfItemsToRemove = int.Parse(Console.ReadLine());

            var iAddables = new IAddable[] { addCollection, addRemoveCollection, myList };

            foreach (var addable in iAddables)
            {
                var indexes = new List <int>();

                foreach (var item in itemsToAdd)
                {
                    indexes.Add(addable.Add(item));
                }

                Console.WriteLine(string.Join(" ", indexes));
            }

            //Only the first item in iAddables does not implement IRemovable so it is excluded. All other items are converted to IRemovable so the Remove() method can be used
            var removables = iAddables.Skip(1).Select(addable => addable as IRemoveable).ToList();

            foreach (var removable in removables)
            {
                var removedItems = new List <string>();

                for (int i = 0; i < numberOfItemsToRemove; i++)
                {
                    removedItems.Add(removable.Remove());
                }

                Console.WriteLine(string.Join(" ", removedItems));
            }
        }
Example #8
0
        public static void Main()
        {
            IAddCollection <string>       addColletion     = new AddCollection <string>();
            IAddRemoveCollection <string> addRemCollection = new AddRemoveCollection <string>();
            IMyList <string> myList = new MyList <string>();

            var itemsToAdd            = Console.ReadLine().Split(' ');
            var removeOperationsCount = int.Parse(Console.ReadLine());

            var addCollAddIndexes    = new StringBuilder();
            var addRemCollAddIndexes = new StringBuilder();
            var myListCollAddIndexes = new StringBuilder();

            foreach (var item in itemsToAdd)
            {
                addCollAddIndexes.Append($"{addColletion.Add(item)} ");
                addRemCollAddIndexes.Append($"{addRemCollection.Add(item)} ");
                myListCollAddIndexes.Append($"{myList.Add(item)} ");
            }

            var addRemCollRemoveElements = new StringBuilder();
            var myListRemoveElements     = new StringBuilder();

            for (int i = 0; i < removeOperationsCount; i++)
            {
                addRemCollRemoveElements.Append($"{addRemCollection.Remove()} ");
                myListRemoveElements.Append($"{myList.Remove()} ");
            }

            Console.WriteLine(addCollAddIndexes.ToString().Trim());
            Console.WriteLine(addRemCollAddIndexes.ToString().Trim());
            Console.WriteLine(myListCollAddIndexes.ToString().Trim());

            Console.WriteLine(addRemCollRemoveElements.ToString().Trim());
            Console.WriteLine(myListRemoveElements.ToString().Trim());
        }
Example #9
0
        private static void printIndexs(string[] elementsToAdd, AddCollection addCollection, AddRemoveCollection addRemoveCollection, MyList myList)
        {
            foreach (var element in elementsToAdd)
            {
                Console.Write(addCollection.Add(element) + " ");
            }
            Console.WriteLine();

            foreach (var element in elementsToAdd)
            {
                Console.Write(addRemoveCollection.Add(element) + " ");
            }
            Console.WriteLine();

            foreach (var element in elementsToAdd)
            {
                Console.Write(myList.Add(element) + " ");
            }
        }